2022-05-11 11:32:11 +02:00
|
|
|
package syncer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-07-04 15:01:44 +02:00
|
|
|
|
2022-05-11 11:32:11 +02:00
|
|
|
"github.com/georgysavva/scany/pgxscan"
|
|
|
|
"github.com/hibiken/asynq"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
2022-07-04 15:01:44 +02:00
|
|
|
func (s *Syncer) UssdSyncer(ctx context.Context, _ *asynq.Task) error {
|
2022-05-11 11:32:11 +02:00
|
|
|
_, err := s.db.Exec(ctx, s.queries["ussd-syncer"])
|
|
|
|
if err != nil {
|
|
|
|
log.Err(err).Msg("ussd syncer task failed")
|
|
|
|
return asynq.SkipRetry
|
|
|
|
}
|
|
|
|
|
|
|
|
var table tableCount
|
|
|
|
if err := pgxscan.Get(ctx, s.db, &table, "SELECT COUNT(*) from users"); err != nil {
|
|
|
|
log.Err(err).Msg("ussd syncer task failed")
|
|
|
|
return asynq.SkipRetry
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info().Msgf("=> %d users synced", table.Count)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|