perf(redis): use sorted set index for O(log N) schedule claiming#14
perf(redis): use sorted set index for O(log N) schedule claiming#14isimisi wants to merge 2 commits into
Conversation
|
Hi! Thanks for the PR. We need a migration path for existing Redis users before merging this. With this change, Can we make the migration automatic/idempotent, or expose and document a required migration step? For example, on startup or first claim, backfill |
|
Hey @RomainLanz, great point. I completely missed the migration path for existing users. I'll add an automatic backfill that runs on startup: on first claimDueSchedule() call (or worker boot), scan schedules::index and populate schedules::due from any schedule that has a next_run_at. I'll make it idempotent so it's safe to run multiple times across worker restarts or multi-instance deployments. |
Existing users upgrading will have schedules in the legacy format (hashes + SET) but not in the new ZSET. Run backfillDueIndex() once per worker process on the first claimDueSchedule() call so schedules keep firing without manual intervention.
|
Hey @RomainLanz, I pushed a follow-up commit that handles the migration automatically. On the first The approach is idempotent ( Does this work for u? Otherwise the we remove the automatic backfill and let users handle it themselves one-time, then we don't need to have a check on |
explanation: #13 (comment)