Skip to content

feat: schedule expired link reports at night - #5347

Open
doubleface wants to merge 5 commits into
masterfrom
feat/expired-report-scheduler
Open

doubleface wants to merge 5 commits into
masterfrom
feat/expired-report-scheduler

Conversation

@doubleface

Copy link
Copy Markdown
Contributor

Summary

  • Scan for opted-in expired file links when drive.public_link_events.enabled is on. Scans start at 02:00 UTC or on startup before 06:00 UTC, and catch up eligible expirations without a fixed lookback. New report work starts only from 02:00 inclusive to 06:00 exclusive UTC; work already started can finish later.
  • Retry safe failures on a later night, but do not automatically replay an ambiguous SMTP submission. This does not guarantee exactly-once delivery or recover imported reports. Recheck the feature flag without the Manager cache, along with the current consent, exact expiry, and recipient before SMTP submission.
  • Open question for Cozy Stack maintainers: do job queues run on native Redis Cluster with multiple redis.addrs and no redis.master? If so, how is the multi-key BRPOP handled when the report queue keys are in different slots? CROSSSLOT can leave report jobs queued and prevent later scans. This topology is not confirmed in production; this PR documents the risk without adding a guard.

@doubleface
doubleface force-pushed the feat/expired-report-mail branch from c2a89a8 to ddb0362 Compare November 22, 2026 22:38
@doubleface
doubleface force-pushed the feat/expired-report-scheduler branch from 313da4a to 63b99e7 Compare November 22, 2026 22:40
@doubleface
doubleface marked this pull request as ready for review November 23, 2026 08:18
Base automatically changed from feat/expired-report-mail to master November 23, 2026 09:07
@shepilov

Copy link
Copy Markdown
Member

Only one stack should make the nightly reports, but today each process runs its own full scan: scanned is local (trigger_expired_links.go:77-78). When the first wave drains, the next process passes the depth check and scans again. This also happens after a restart in the window, and on processes where the worker's concurrency is 0.

Suggestion: under the existing scan lock, check a "this night's scan is done" marker in the jobs Redis, e.g. j/expired-link-report-mail/scanned/<window date>. Skip the scan if the marker exists. After a successful scan, SET it with a TTL until the window ends. If the marker is lost, the worst case is one extra scan.

@doubleface

Copy link
Copy Markdown
Contributor Author

Thanks @shepilov, I went with your suggestion. The scanner checks a per-window marker in the jobs Redis under the existing scan lock. It writes the marker only after a complete scan, with a TTL to the end of the window. That prevents another producer from rescanning after the queue drains or after a restart, even if it has no local workers.

Failed or cancelled scans leave no marker and can retry within the window. The marker records scan completion, not report delivery.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants