cic-dw/cmd/ussd_syncer.go
Mohammed Sohail 9c6310440c
refactor: syncer structure and async bootstrapping
- asynq bootstrap handlers
- graceful shutdown of goroutines
- remove unnecessary global App struct
- unmarhsal toml/env to koanf struct
2022-05-05 15:01:34 +03:00

25 lines
490 B
Go

package main
import (
"context"
"github.com/georgysavva/scany/pgxscan"
"github.com/hibiken/asynq"
"github.com/rs/zerolog/log"
)
func ussdSyncer(ctx context.Context, t *asynq.Task) error {
_, err := db.Exec(ctx, queries["ussd-syncer"])
if err != nil {
return asynq.SkipRetry
}
var count tableCount
if err := pgxscan.Get(ctx, db, &count, "SELECT COUNT(*) from users"); err != nil {
return asynq.SkipRetry
}
log.Info().Msgf("=> %d users synced", count.Count)
return nil
}