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

fix(core): Account for cancelling an execution with no workers available #10343

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/cli/src/scaling/__tests__/scaling.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ describe('ScalingService', () => {
expect(jobs).toHaveLength(1);
expect(jobs.at(0)?.id).toBe('123');
});

it('should filter out `null` in Redis response', async () => {
/**
* Arrange
*/
const scalingService = new ScalingService(mock(), mock(), mock());
await scalingService.setupQueue();
// @ts-expect-error - Untyped but possible Redis response
queue.getJobs.mockResolvedValue([mock<Job>(), null]);

/**
* Act
*/
const jobs = await scalingService.findJobsByStatus(['waiting']);

/**
* Assert
*/
expect(jobs).toHaveLength(1);
});
});

describe('stopJob', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/scaling/scaling.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export class ScalingService {
}

async findJobsByStatus(statuses: JobStatus[]) {
return await this.queue.getJobs(statuses);
const jobs = await this.queue.getJobs(statuses);

return jobs.filter((job) => job !== null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case can the Job be null? A comment would be in order since according to the function types it should never return a null

}

async stopJob(job: Job) {
Expand Down
Loading