From b74eacd23a6bdaaa903fd2ef3e52bf8d3b57475d Mon Sep 17 00:00:00 2001 From: Taras Kushnir Date: Sun, 17 Aug 2025 21:41:37 +0300 Subject: [PATCH] Cosmetic improvements --- cmd/server/main.go | 2 +- pkg/maintenance/email.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 6f6e4ea6..3d565c49 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -338,7 +338,7 @@ func run(ctx context.Context, cfg common.ConfigStore, stderr io.Writer, listener Store: businessDB, }) jobs.AddLocked(1*time.Hour, &maintenance.UserEmailNotificationsJob{ - RunInterval: 1 * time.Hour, + RunInterval: 3 * time.Hour, // overlap few locked intervals to cover for possible unprocessed notifications Store: businessDB, Templates: email.Templates(), Sender: sender, diff --git a/pkg/maintenance/email.go b/pkg/maintenance/email.go index 7efe4812..520ca7f1 100644 --- a/pkg/maintenance/email.go +++ b/pkg/maintenance/email.go @@ -193,7 +193,13 @@ func (j *UserEmailNotificationsJob) retrievePendingNotifications(ctx context.Con return filtered, nil } +// NOTE: we should NOT refactor this into "while we have pending notifications {}" loop because some notifications +// are unprocessable by design (e.g. "subscribed-only" notifications for users who don't have subscriptions), therefore +// there are cases when there will always be "pending" notifications. +// If we are not managing to process all of them, we need to modify ChunkSize and Interval (or Lock Inteval) instead func (j *UserEmailNotificationsJob) RunOnce(ctx context.Context) error { + // TODO: Monitor pending notifications count in Postgres + // so we will know if we have enough processing capacity notifications, err := j.retrievePendingNotifications(ctx) if err != nil { slog.ErrorContext(ctx, "Failed to retrieve pending user notifications", common.ErrAttr(err))