2022-05-03 20:37:48 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/georgysavva/scany/pgxscan"
|
|
|
|
"github.com/hibiken/asynq"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type tableCount struct {
|
|
|
|
Count int `db:"count"`
|
|
|
|
}
|
|
|
|
|
2022-05-05 14:01:34 +02:00
|
|
|
func cacheSyncer(ctx context.Context, t *asynq.Task) error {
|
|
|
|
_, err := db.Exec(ctx, queries["cache-syncer"])
|
2022-05-03 20:37:48 +02:00
|
|
|
if err != nil {
|
|
|
|
return asynq.SkipRetry
|
|
|
|
}
|
|
|
|
|
|
|
|
var count tableCount
|
2022-05-05 14:01:34 +02:00
|
|
|
if err := pgxscan.Get(ctx, db, &count, "SELECT COUNT(*) from transactions"); err != nil {
|
2022-05-03 20:37:48 +02:00
|
|
|
return asynq.SkipRetry
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info().Msgf("=> %d transactions synced", count.Count)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|