Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class Queue<
* @returns The next job to be scheduled (would normally be in delayed state).
*/
async upsertJobScheduler(
jobSchedulerId: NameType,
jobSchedulerId: string,
repeatOpts: Omit<RepeatOptions, 'key'>,
jobTemplate?: {
name?: NameType;
Expand All @@ -487,7 +487,7 @@ export class Queue<
>(
jobSchedulerId,
repeatOpts,
jobTemplate?.name ?? jobSchedulerId,
jobTemplate?.name ?? (jobSchedulerId as NameType),
jobTemplate?.data ?? <DataType>{},
{ ...this.jobsOpts, ...jobTemplate?.opts },
{ override: true },
Expand Down
31 changes: 31 additions & 0 deletions tests/job_scheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,37 @@ describe('Job Scheduler', () => {
});
});

// Regression for https://github.com/taskforcesh/bullmq/issues/3937:
// the scheduler id is an identity (e.g. a per-instance UUID) and must
// not inherit the queue's NameType constraint — otherwise typed
// queues reject any scheduler id that isn't also a job-name literal.
describe('when the queue has a constrained NameType', () => {
it('accepts a free-string scheduler id distinct from any job name', async () => {
type ReportJobs = 'generate-report' | 'send-email';
const typedQueueName = `typed-${randomUUID()}`;
const typedQueue = new Queue<unknown, unknown, ReportJobs>(
typedQueueName,
{ connection, prefix },
);
await typedQueue.waitUntilReady();

try {
const dynamicInstanceId = `inst_${randomUUID()}`;
const job = await typedQueue.upsertJobScheduler(
dynamicInstanceId,
{ every: 60_000 },
{ name: 'generate-report', data: {} },
);

expect(job!.repeatJobKey).toBeDefined();
expect(job!.name).toBe('generate-report');
} finally {
await typedQueue.close();
await removeAllQueueData(new IORedis(redisHost), typedQueueName);
}
});
});

it('it should stop repeating after endDate', async () => {
const every = 100;
const date = new Date('2017-02-07 9:24:00');
Expand Down
Loading