From e1fcb8395ed52d7605d2ee907e96c2a8da314c27 Mon Sep 17 00:00:00 2001 From: trpdjke Date: Fri, 9 Aug 2024 11:46:53 +0300 Subject: [PATCH] remade start event --- internal/cli/event.go | 18 ++++++++++++++++++ internal/data/evtypes/init.go | 21 +++++++++++++++++++++ internal/data/evtypes/main.go | 4 ---- internal/service/event/main.go | 1 + internal/service/router.go | 4 ++-- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/internal/cli/event.go b/internal/cli/event.go index 0f93d41..2a45fa9 100644 --- a/internal/cli/event.go +++ b/internal/cli/event.go @@ -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) diff --git a/internal/data/evtypes/init.go b/internal/data/evtypes/init.go index 1dec196..f6f4380 100644 --- a/internal/data/evtypes/init.go +++ b/internal/data/evtypes/init.go @@ -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...) +} diff --git a/internal/data/evtypes/main.go b/internal/data/evtypes/main.go index c756175..bc9b4ea 100644 --- a/internal/data/evtypes/main.go +++ b/internal/data/evtypes/main.go @@ -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" ) @@ -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") } } diff --git a/internal/service/event/main.go b/internal/service/event/main.go index 23e2521..b2c51ef 100644 --- a/internal/service/event/main.go +++ b/internal/service/event/main.go @@ -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) diff --git a/internal/service/router.go b/internal/service/router.go index 077fd95..f714c24 100644 --- a/internal/service/router.go +++ b/internal/service/router.go @@ -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) @@ -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) {