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

This commit is contained in:
Iván Ovejero 2024-08-12 11:03:51 +02:00 committed by GitHub
parent 8728b63aeb
commit b044e783e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -190,6 +190,26 @@ describe('ScalingService', () => {
expect(jobs).toHaveLength(1); expect(jobs).toHaveLength(1);
expect(jobs.at(0)?.id).toBe('123'); 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', () => { describe('stopJob', () => {

View file

@ -88,7 +88,9 @@ export class ScalingService {
} }
async findJobsByStatus(statuses: JobStatus[]) { async findJobsByStatus(statuses: JobStatus[]) {
return await this.queue.getJobs(statuses); const jobs = await this.queue.getJobs(statuses);
return jobs.filter((job) => job !== null);
} }
async stopJob(job: Job) { async stopJob(job: Job) {