Skip to content

Commit

Permalink
remade start event
Browse files Browse the repository at this point in the history
  • Loading branch information
kish1n committed Aug 9, 2024
1 parent f359ebb commit e1fcb83
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
18 changes: 18 additions & 0 deletions internal/cli/event.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
package cli

import (
"fmt"
"sync"

"github.com/rarimo/geo-points-svc/internal/config"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/service/event"
)

func eventStart(cfg config.Config, data int) {
var evTypesSig = make(chan struct{})
wg := &sync.WaitGroup{}
run := func(f func()) {
wg.Add(1)
go func() {
f()
wg.Done()
}()
}

run(func() { evtypes.InitFoOneTimeEvent(cfg, evTypesSig) })
<-evTypesSig

fmt.Println("ini end")
err := event.Run(cfg, data)
if err != nil {
cfg.Log().Errorf("Error starting event: %s", err)
Expand Down
21 changes: 21 additions & 0 deletions internal/data/evtypes/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,24 @@ func Init(_ context.Context, cfg extConfig, sig chan struct{}) {
log.Debugf("Adding/overwriting event types from DB: %+v", dbTypes)
types.Push(dbTypes...)
}

func InitFoOneTimeEvent(cfg extConfig, sig chan struct{}) {
var (
log = cfg.Log().WithField("who", "evtypes")
q = pg.NewEventTypes(cfg.DB().Clone())
types = cfg.EventTypes()
)

dbTypes, err := q.New().Select()
if err != nil {
panic(fmt.Errorf("select all event types: %w", err))
}

defer func() {
types.dbSynced = true
sig <- struct{}{}
}()

log.Debugf("Adding/overwriting event types from DB: %+v", dbTypes)
types.Push(dbTypes...)
}
4 changes: 0 additions & 4 deletions internal/data/evtypes/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package evtypes

import (
"fmt"

"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
)
Expand Down Expand Up @@ -93,8 +91,6 @@ func (t *Types) Push(types ...models.EventType) {

func (t *Types) ensureInitialized() {
if t.m == nil || t.list == nil || !t.dbSynced {
txt := fmt.Sprintf("t.m - %+v, t.lisy - %+v, t.dbSynced %+v", t.m, t.list, t.dbSynced)
fmt.Println(txt)
panic("event types are not correctly initialized")
}
}
1 change: 1 addition & 0 deletions internal/service/event/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Run(cfg config.Config, date int) error {
referralsQ := pg.NewReferrals(db)

evType := evTypes.Get(models.TypeEarlyTest, evtypes.FilterInactive)

log.Infof("point")
if evType == nil {
log.Infof("Event type %s is inactive", models.TypeEarlyTest)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Run(ctx context.Context, cfg config.Config) {
r.Route("/integrations/geo-points-svc/v1", func(r chi.Router) {
r.Route("/public", func(r chi.Router) {
r.Route("/balances", func(r chi.Router) {
r.Use(authMW)
//r.Use(authMW)
r.Post("/", handlers.CreateBalance)
r.Route("/{nullifier}", func(r chi.Router) {
r.Get("/", handlers.GetBalance)
Expand All @@ -46,7 +46,7 @@ func Run(ctx context.Context, cfg config.Config) {

})
r.Route("/events", func(r chi.Router) {
r.Use(authMW)
//r.Use(authMW)
r.Get("/", handlers.ListEvents)
r.Post("/poll", handlers.FulfillPollEvent)
r.Route("/{id}", func(r chi.Router) {
Expand Down

0 comments on commit e1fcb83

Please sign in to comment.