Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Job scheduler creates multiple delayed jobs when upserting in quick succession #2988

Closed
1 task done
tjhiggins opened this issue Dec 30, 2024 · 4 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@tjhiggins
Copy link

tjhiggins commented Dec 30, 2024

Version

v5.34.5

Platform

NodeJS

What happened?

If you call upsertJobScheduler in quick succession it will create multiple delayed jobs for the same scheduler.

How to reproduce.

Took me awhile to reproduce. Needed to have a worker defined. I also struggled to get it to fail consistently with the fake clock...

Test: d6117a0#diff-a19149ca7b4f2a0cee7cff833e33245c005ef785fc0a7ac3616a11b79148a21fR213

Relevant log output

Struggled to make it fail every time with the fake clock, but here is an example failure:

$ yarn test -g 'when job schedulers are upserted in quick succession'
yarn run v1.22.22
$ npm-run-all clean:scripts generate:raw:scripts transform:commands
$ rimraf rawScripts src/scripts
$ ts-node --project tsconfig-cjs.json scripts/generateRawScripts.ts
$ node ./scripts/commandTransform.js ./rawScripts ./src/scripts
$ ts-mocha -p tsconfig-cjs.json --config ./.mocharc.js -g 'when job schedulers are upserted in quick succession'


  Job Scheduler
    when job schedulers are upserted in quick succession
      1) should create only one job scheduler and one delayed job


  0 passing (58ms)
  1 failing

  1) Job Scheduler
       when job schedulers are upserted in quick succession
         should create only one job scheduler and one delayed job:

      AssertionError: expected [ Job{ …(22) }, Job{ …(22) } ] to have a length of 1 but got 2
      + expected - actual

      -2
      +1
      
      at Context.<anonymous> (tests/test_job_scheduler.ts:254:31)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)



error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tjhiggins tjhiggins added the bug Something isn't working label Dec 30, 2024
@tjhiggins
Copy link
Author

tjhiggins commented Dec 30, 2024

If the test passes - try adding more schedulers

Ex.

await queue.upsertJobScheduler(jobSchedulerId, {
  every: ONE_MINUTE * 5,
});

await this.clock.tickAsync(1);

await queue.upsertJobScheduler(jobSchedulerId, {
  every: ONE_MINUTE * 5,
});

await queue.upsertJobScheduler(jobSchedulerId, {
  every: ONE_MINUTE * 5,
});

await queue.upsertJobScheduler(jobSchedulerId, {
  every: ONE_MINUTE * 5,
});

@manast
Copy link
Contributor

manast commented Dec 31, 2024

Thanks for reporting this. I will investigate ASAP.

@manast
Copy link
Contributor

manast commented Dec 31, 2024

Ok, I think I found why this happens in this scenario. With a bit of luck a fix will be available before years end :)

@tjhiggins
Copy link
Author

@manast Lucky indeed. I can confirm that the issue is fixed. Appreciate the quick turnaround. Happy new year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants