diff --git a/internal/cmd/scheduler.go b/internal/cmd/scheduler.go index 7129a0f..08948d0 100644 --- a/internal/cmd/scheduler.go +++ b/internal/cmd/scheduler.go @@ -96,12 +96,14 @@ func SchedulerCmd(ctx context.Context) *cobra.Command { s := gocron.NewScheduler(time.UTC) s.SetMaxConcurrentJobs(8, gocron.WaitMode) - _, _ = s.Every(5).Seconds().SingletonMode().Do(func() { enqueueAccounts(ctx, logger, statsd, db, redis, luaSha, notifQueue) }) - _, _ = s.Every(5).Second().Do(func() { enqueueSubreddits(ctx, logger, statsd, db, []rmq.Queue{subredditQueue, trendingQueue}) }) - _, _ = s.Every(5).Second().Do(func() { enqueueUsers(ctx, logger, statsd, db, userQueue) }) - _, _ = s.Every(5).Second().Do(func() { enqueueLiveActivities(ctx, logger, db, redis, luaSha, liveActivitiesQueue) }) - _, _ = s.Every(5).Second().Do(func() { cleanQueues(logger, queue) }) - _, _ = s.Every(5).Second().Do(func() { enqueueStuckAccounts(ctx, logger, statsd, db, stuckNotificationsQueue) }) + eaj, _ := s.Every(5).Seconds().Do(func() { enqueueAccounts(ctx, logger, statsd, db, redis, luaSha, notifQueue) }) + eaj.SingletonMode() + + _, _ = s.Every(5).Seconds().Do(func() { enqueueSubreddits(ctx, logger, statsd, db, []rmq.Queue{subredditQueue, trendingQueue}) }) + _, _ = s.Every(5).Seconds().Do(func() { enqueueUsers(ctx, logger, statsd, db, userQueue) }) + _, _ = s.Every(5).Seconds().Do(func() { enqueueLiveActivities(ctx, logger, db, redis, luaSha, liveActivitiesQueue) }) + _, _ = s.Every(5).Seconds().Do(func() { cleanQueues(logger, queue) }) + _, _ = s.Every(5).Seconds().Do(func() { enqueueStuckAccounts(ctx, logger, statsd, db, stuckNotificationsQueue) }) _, _ = s.Every(1).Minute().Do(func() { reportStats(ctx, logger, statsd, db) }) //_, _ = s.Every(1).Minute().Do(func() { pruneAccounts(ctx, logger, db) }) //_, _ = s.Every(1).Minute().Do(func() { pruneDevices(ctx, logger, db) }) diff --git a/internal/repository/postgres_account.go b/internal/repository/postgres_account.go index 4665684..07d6584 100644 --- a/internal/repository/postgres_account.go +++ b/internal/repository/postgres_account.go @@ -86,12 +86,12 @@ func (p *postgresAccountRepository) CreateOrUpdate(ctx context.Context, acc *dom query := ` INSERT INTO accounts (username, reddit_account_id, access_token, refresh_token, token_expires_at, last_message_id, next_notification_check_at, next_stuck_notification_check_at, is_deleted) - VALUES ($1, $2, $3, $4, $5, '', NOW(), NOW(), false) + VALUES ($1, $2, $3, $4, $5, '', NOW(), NOW(), FALSE) ON CONFLICT(username) DO UPDATE SET access_token = $3, refresh_token = $4, token_expires_at = $5, - is_deleted = false + is_deleted = FALSE RETURNING id` return p.conn.QueryRow( @@ -110,7 +110,7 @@ func (p *postgresAccountRepository) Create(ctx context.Context, acc *domain.Acco INSERT INTO accounts (username, reddit_account_id, access_token, refresh_token, token_expires_at, last_message_id, next_notification_check_at, next_stuck_notification_check_at, is_deleted) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, false) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, FALSE) RETURNING id` return p.conn.QueryRow(