Skip to content

Commit

Permalink
event.Run fix loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kish1n committed Aug 8, 2024
1 parent 5ec8bc7 commit 2f4b866
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Run(args []string) bool {

event = app.Command("event", "claim event command")
eventCmd = event.Command("create-early-test", "claim event command")
data = eventCmd.Arg("before", "data after ...").Required().Int()
date = eventCmd.Arg("before", "date after ...").Required().Int()
)

cmd, err := app.Parse(args[1:])
Expand All @@ -53,7 +53,7 @@ func Run(args []string) bool {
case migrateDownCmd.FullCommand():
err = MigrateDown(cfg)
case eventCmd.FullCommand():
eventStart(cfg, *data)
eventStart(cfg, *date)
default:
log.Errorf("unknown command %s", cmd)
return false
Expand Down
4 changes: 4 additions & 0 deletions internal/data/evtypes/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 @@ -91,6 +93,8 @@ 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")
}
}
6 changes: 4 additions & 2 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)
return nil
Expand All @@ -45,6 +46,7 @@ func Run(cfg config.Config, date int) error {
}

filteredEvents, err := eventsQ.
FilterByType(models.TypeEarlyTest).
FilterByStatus(data.EventFulfilled).
FilterByNullifier(nullifiers...).
Select()
Expand All @@ -60,7 +62,7 @@ func Run(cfg config.Config, date int) error {
}

for _, balance := range balances {
err = eventsQ.Transaction(func() error {
err = eventsQ.New().Transaction(func() error {
if _, exists := eventsMap[balance.Nullifier]; exists {
return nil
}
Expand All @@ -82,7 +84,7 @@ func Run(cfg config.Config, date int) error {

_, err = eventsQ.FilterByNullifier(balance.Nullifier).Update(data.EventClaimed, nil, &evType.Reward)
if err != nil {
return fmt.Errorf("failedt to update %s events for user=%s: %w", models.TypeEarlyTest, balance.Nullifier, err)
return fmt.Errorf("failed to update %s events for user=%s: %w", models.TypeEarlyTest, balance.Nullifier, err)
}

totalPoints += evType.Reward
Expand Down

0 comments on commit 2f4b866

Please sign in to comment.