Skip to content

Commit f6270f8

Browse files
authoredDec 12, 2024··
fix: correct waitForCompletion behavior (#924)
<!--- Provide a general summary of your changes in the Title above (following the Conventional Commits standard) --> <!-- More infos: https://www.conventionalcommits.org --> <!-- Commit types: https://github.com/insurgent-lab/conventional-changelog-preset#commit-types--> ## Description <!--- Describe your changes in detail --> fixes #923 ## Related Issue <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> #923 ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> it makes the new feature actually work ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> modified test case added by #894 ## Screenshots (if appropriate): ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have added tests to cover my changes. - [x] All new and existing tests passed. - [ ] If my change introduces a breaking change, I have added a `!` after the type/scope in the title (see the Conventional Commits standard).
1 parent f4e9e02 commit f6270f8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎src/job.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ export class CronJob<OC extends CronOnCompleteCommand | null = null, C = null> {
207207
}
208208

209209
async fireOnTick() {
210-
if (!this.waitForCompletion && this._isCallbackRunning) return;
210+
// skip job if previous callback is still running
211+
if (this.waitForCompletion && this._isCallbackRunning) return;
211212

212213
this._isCallbackRunning = true;
213214

‎tests/cron.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1231,10 +1231,12 @@ describe('cron', () => {
12311231
it('should track multiple running jobs correctly', async () => {
12321232
const clock = sinon.useFakeTimers();
12331233
const executionOrder: number[] = [];
1234+
let started = 0;
12341235

12351236
const job = new CronJob(
12361237
'* * * * * *',
12371238
async () => {
1239+
started++;
12381240
await new Promise<void>(resolve => {
12391241
setTimeout(() => {
12401242
callback();
@@ -1256,7 +1258,8 @@ describe('cron', () => {
12561258

12571259
await clock.tickAsync(3500);
12581260

1259-
expect(executionOrder).toEqual([1, 2]);
1261+
expect(started).toBe(2);
1262+
expect(executionOrder).toEqual([1]);
12601263
job.stop();
12611264
});
12621265

0 commit comments

Comments
 (0)
Please sign in to comment.