-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
package cli | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/rarimo/geo-points-svc/internal/config" | ||
"github.com/rarimo/geo-points-svc/internal/service/event" | ||
) | ||
|
||
func eventStart(cfg config.Config, data int) { | ||
err := event.Run(cfg, data) | ||
if err != nil { | ||
log.Fatalf("Error starting event: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,55 @@ | ||
package event | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/rarimo/geo-points-svc/internal/config" | ||
"github.com/rarimo/geo-points-svc/internal/data" | ||
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models" | ||
"github.com/rarimo/geo-points-svc/internal/data/pg" | ||
) | ||
|
||
func Run(cfg config.Config, date int) error { | ||
log := cfg.Log() | ||
db := cfg.DB() | ||
|
||
balances := pg.NewBalances(db) | ||
events := pg.NewEvents(db) | ||
|
||
users, err := balances.FilterByCreatedBefore(date).FilterVerified().Select() | ||
filtEvents := events.FilterByType(models.TypeEarlyTest) | ||
|
||
if err != nil { | ||
log.WithError(err).Error("failed to filter by updated before") | ||
return err | ||
} | ||
|
||
if users == nil { | ||
log.Infof("no users found") | ||
return nil | ||
} | ||
|
||
for _, user := range users { | ||
userNull := user.Nullifier | ||
eve, err := filtEvents.FilterByNullifier(userNull).Get() | ||
|
||
if err != nil { | ||
log.WithError(err).Error("failed to filter by nullifier") | ||
return err | ||
} | ||
if eve != nil { | ||
break | ||
} | ||
|
||
err = events.Insert(data.Event{ | ||
Nullifier: user.Nullifier, | ||
Type: models.TypeEarlyTest, | ||
Status: data.EventFulfilled, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("failed to insert `early_test` event: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,4 @@ func Run(cfg config.Config, sig chan struct{}) { | |
} | ||
|
||
sig <- struct{}{} | ||
|
||
} |