Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Sep 13, 2024
1 parent 7264d3a commit adb5f29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,32 @@ describe('TaskManagerRunner', () => {

expect(runner.isAdHocTaskAndOutOfAttempts).toEqual(true);
});

it(`should return true if attempts = max attempts and in claiming status`, async () => {
const { runner } = await pendingStageSetup({
instance: {
id: 'foo',
taskType: 'testbar',
attempts: 5,
status: TaskStatus.Claiming,
},
});

expect(runner.isAdHocTaskAndOutOfAttempts).toEqual(true);
});

it(`should return false if attempts = max attempts and in running status`, async () => {
const { runner } = await pendingStageSetup({
instance: {
id: 'foo',
taskType: 'testbar',
attempts: 5,
status: TaskStatus.Running,
},
});

expect(runner.isAdHocTaskAndOutOfAttempts).toEqual(false);
});
});

describe('removeTask()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ export class TaskManagerRunner implements TaskRunner {
* running a task, the task should be deleted instead of ran.
*/
public get isAdHocTaskAndOutOfAttempts() {
if (this.instance.task.status === 'running') {
// This function gets called with tasks marked as running when using MGET, so attempts is already incremented
return !this.instance.task.schedule && this.instance.task.attempts > this.getMaxAttempts();
}
return !this.instance.task.schedule && this.instance.task.attempts >= this.getMaxAttempts();
}

Expand Down

0 comments on commit adb5f29

Please sign in to comment.