fix(scheduler): correctly identify schedulers with 5+ segment ids (#3499) - #4056
fix(scheduler): correctly identify schedulers with 5+ segment ids (#3499)#4056maruthang wants to merge 5 commits into
Conversation
…askforcesh#3499) When a job scheduler id contains 5 or more colon-separated segments (for example "calculate:trending:subjects:tenant:instanceId-XXXXX"), the worker misclassified the scheduled job as a legacy repeatable job and routed it through the legacy `repeat.updateRepeatableJob` path. That path is a no-op for `every`-only schedulers, so the scheduler's `next` value stayed in the past and `iterationCount` remained at 1 forever, meaning the job never ran a second time. Replace the segment-count-only discriminator with a metadata probe: the new `JobScheduler.isJobScheduler` checks `HEXISTS repeat:<id> ic`, where the `ic` field is written exclusively by `storeJobScheduler` and never by the legacy `addRepeatableJob` flow. The worker keeps the cheap segment-count fast path for ids with fewer than 5 segments and only consults Redis when the shape is ambiguous, so there is no extra round trip for the common case. Add a regression test that creates a scheduler with 5 colon segments, processes the first job, and asserts that `next` advances and that `iterationCount` increments past 1.
…peated-job-next-advance # Conflicts: # src/classes/worker.ts # tests/job_scheduler.test.ts
|
Rebased on master. While resolving conflicts I found master has since landed an equivalent fix (the |
|
CI note: the single remaining red job ( |
Why
Closes #3499. The worker disambiguates a job scheduler vs a legacy repeatable job by counting
:segments inrepeatJobKey— if there are fewer than 5, treat it as a scheduler. Any user-providedjobSchedulerIdwith 5+ colon segments (e.g.calculate:trending:subjects:tenant:instanceId-XXXXXfrom the report) was misrouted to the legacyrepeat.updateRepeatableJobpath, which is a no-op forevery-only schedulers. The result:nextstayed in the past anditerationCountwas stuck at 1, so the job never ran a second time.How
isJobScheduler(id)insrc/classes/job-scheduler.ts. It probesHEXISTS repeat:<id> ic— theic(iteration count) field is only written bystoreJobScheduler, never by the legacy repeatable flow, so it's a reliable discriminator.src/classes/worker.ts, kept the cheap<5 segmentsfast path; for ambiguous 5+ segment shapes, the worker now consultsisJobSchedulerbefore falling back to the legacy path.tests/job_scheduler.test.tsasserting thatnextadvances anditerationCountincrements after the first job runs for a 5-segment scheduler id. The test fails without the fix (expected 1486439640000 to be greater than 1486439640000) and passes with it.Additional Notes
HEXISTSround-trip only when the segment count is ambiguous.tests/job_scheduler.test.tssuite: 74 passing / 1 pre-existing failure (should create job schedulers with different cron patterns— also fails onmaster, unrelated).