From 3402bfe0d01e5e5205db74d2106cd19d7df53fcb Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Wed, 4 Dec 2024 00:16:32 -0600 Subject: [PATCH] fix(scheduler-template): remove console.log when getting template information (#2950) --- src/classes/job-scheduler.ts | 10 +++++++--- src/classes/job.ts | 14 -------------- src/classes/queue-base.ts | 2 +- src/commands/addParentJob-4.lua | 6 +++--- src/commands/includes/removeDeduplicationKey.lua | 1 - src/interfaces/base-job-options.ts | 4 +++- src/interfaces/parent.ts | 1 + src/types/job-json-sandbox.ts | 2 +- tests/test_bulk.ts | 13 +++++-------- tests/test_job_scheduler.ts | 4 ++-- tests/test_repeat.ts | 4 ++-- tests/test_worker.ts | 9 +++++---- 12 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/classes/job-scheduler.ts b/src/classes/job-scheduler.ts index 344c96014e..1f3493c6e6 100644 --- a/src/classes/job-scheduler.ts +++ b/src/classes/job-scheduler.ts @@ -1,8 +1,13 @@ import { parseExpression } from 'cron-parser'; -import { RedisClient, RepeatBaseOptions, RepeatOptions } from '../interfaces'; +import { + JobSchedulerJson, + JobSchedulerTemplateJson, + RedisClient, + RepeatBaseOptions, + RepeatOptions, +} from '../interfaces'; import { JobsOptions, RepeatStrategy } from '../types'; import { Job } from './job'; -import { JobSchedulerJson, JobSchedulerTemplateJson } from '../interfaces'; import { QueueBase } from './queue-base'; import { RedisConnection } from './redis-connection'; import { SpanKind, TelemetryAttributes } from '../enums'; @@ -264,7 +269,6 @@ export class JobScheduler extends QueueBase { rawData?: string, rawOpts?: string, ): JobSchedulerTemplateJson { - console.log(typeof rawOpts); const template: JobSchedulerTemplateJson = {}; if (rawData) { template.data = JSON.parse(rawData); diff --git a/src/classes/job.ts b/src/classes/job.ts index 21a73cff81..5ac56fea75 100644 --- a/src/classes/job.ts +++ b/src/classes/job.ts @@ -19,11 +19,9 @@ import { JobState, JobJsonSandbox, MinimalQueue, - RedisJobOptions, } from '../types'; import { errorObject, - invertObject, isEmpty, getParentKey, lengthInUtf8Bytes, @@ -41,18 +39,6 @@ import { SpanKind } from '../enums'; const logger = debuglog('bull'); -const optsDecodeMap = { - de: 'deduplication', - fpof: 'failParentOnFailure', - idof: 'ignoreDependencyOnFailure', - kl: 'keepLogs', - rdof: 'removeDependencyOnFailure', - tm: 'telemetryMetadata', -}; - -const optsEncodeMap = invertObject(optsDecodeMap); -optsEncodeMap.debounce = 'de'; - export const PRIORITY_LIMIT = 2 ** 21; /** diff --git a/src/classes/queue-base.ts b/src/classes/queue-base.ts index 9e2008f958..b355f90014 100644 --- a/src/classes/queue-base.ts +++ b/src/classes/queue-base.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import { QueueBaseOptions, RedisClient, Span, Tracer } from '../interfaces'; +import { QueueBaseOptions, RedisClient, Span } from '../interfaces'; import { MinimalQueue } from '../types'; import { delay, diff --git a/src/commands/addParentJob-4.lua b/src/commands/addParentJob-4.lua index 0840037e5f..bde421fca8 100644 --- a/src/commands/addParentJob-4.lua +++ b/src/commands/addParentJob-4.lua @@ -3,13 +3,13 @@ - Increases the job counter if needed. - Creates a new job key with the job data. - adds the job to the waiting-children zset - + Input: KEYS[1] 'meta' KEYS[2] 'id' KEYS[3] 'completed' KEYS[4] events stream key - + ARGV[1] msgpacked arguments array [1] key prefix, [2] custom id (will not generate one automatically) @@ -21,7 +21,7 @@ [8] parent? {id, queueKey} [9] repeat job key [10] deduplication key - + ARGV[2] Json stringified job data ARGV[3] msgpacked options diff --git a/src/commands/includes/removeDeduplicationKey.lua b/src/commands/includes/removeDeduplicationKey.lua index b93e9e29f8..a4b2a461d7 100644 --- a/src/commands/includes/removeDeduplicationKey.lua +++ b/src/commands/includes/removeDeduplicationKey.lua @@ -9,4 +9,3 @@ local function removeDeduplicationKey(prefixKey, jobKey) rcall("DEL", deduplicationKey) end end - \ No newline at end of file diff --git a/src/interfaces/base-job-options.ts b/src/interfaces/base-job-options.ts index bb10f1caa3..269309263b 100644 --- a/src/interfaces/base-job-options.ts +++ b/src/interfaces/base-job-options.ts @@ -1,4 +1,6 @@ -import { RepeatOptions, KeepJobs, BackoffOptions } from './'; +import { BackoffOptions } from './backoff-options'; +import { KeepJobs } from './keep-jobs'; +import { RepeatOptions } from './repeat-options'; export interface DefaultJobOptions { /** diff --git a/src/interfaces/parent.ts b/src/interfaces/parent.ts index 8dd1fc0a92..ea00482321 100644 --- a/src/interfaces/parent.ts +++ b/src/interfaces/parent.ts @@ -1,4 +1,5 @@ import { JobsOptions } from '../types'; + /** * Describes the parent for a Job. */ diff --git a/src/types/job-json-sandbox.ts b/src/types/job-json-sandbox.ts index c1a96d96a6..3181fbc3f8 100644 --- a/src/types/job-json-sandbox.ts +++ b/src/types/job-json-sandbox.ts @@ -1,4 +1,4 @@ -import { JobJson, ParentKeys } from '../interfaces'; +import { JobJson } from '../interfaces'; export type JobJsonSandbox = JobJson & { queueName: string; diff --git a/tests/test_bulk.ts b/tests/test_bulk.ts index 1d6b8eb4ec..a3729885bc 100644 --- a/tests/test_bulk.ts +++ b/tests/test_bulk.ts @@ -85,7 +85,7 @@ describe('bulk jobs', () => { data: { idx: 0, foo: 'bar' }, opts: { parent: { - id: parent.id, + id: parent.id!, queue: `${prefix}:${parentQueueName}`, }, }, @@ -95,7 +95,7 @@ describe('bulk jobs', () => { data: { idx: 1, foo: 'baz' }, opts: { parent: { - id: parent.id, + id: parent.id!, queue: `${prefix}:${parentQueueName}`, }, }, @@ -122,22 +122,20 @@ describe('bulk jobs', () => { it('should keep workers busy', async () => { const numJobs = 6; - const queue2 = new Queue(queueName, { connection, markerCount: 2, prefix }); - const queueEvents = new QueueEvents(queueName, { connection, prefix }); await queueEvents.waitUntilReady(); const worker = new Worker( queueName, async () => { - await delay(1000); + await delay(900); }, { connection, prefix }, ); const worker2 = new Worker( queueName, async () => { - await delay(1000); + await delay(900); }, { connection, prefix }, ); @@ -153,10 +151,9 @@ describe('bulk jobs', () => { data: { index }, })); - await queue2.addBulk(jobs); + await queue.addBulk(jobs); await completed; - await queue2.close(); await worker.close(); await worker2.close(); await queueEvents.close(); diff --git a/tests/test_job_scheduler.ts b/tests/test_job_scheduler.ts index f0f3244af8..2066679fe0 100644 --- a/tests/test_job_scheduler.ts +++ b/tests/test_job_scheduler.ts @@ -1211,7 +1211,7 @@ describe('Job Scheduler', function () { }); it('should repeat 7:th day every month at 9:25', async function () { - this.timeout(15000); + this.timeout(8000); const date = new Date('2017-02-02 7:21:42'); this.clock.setSystemTime(date); @@ -1260,7 +1260,7 @@ describe('Job Scheduler', function () { worker.run(); - await queue.upsertJobScheduler('repeat', { pattern: '* 25 9 7 * *' }); + await queue.upsertJobScheduler('repeat', { pattern: '25 9 7 * *' }); nextTick(); await completing; diff --git a/tests/test_repeat.ts b/tests/test_repeat.ts index ed6ee6e301..44d7125e5b 100644 --- a/tests/test_repeat.ts +++ b/tests/test_repeat.ts @@ -1110,7 +1110,7 @@ describe('repeat', function () { }); it('should repeat 7:th day every month at 9:25', async function () { - this.timeout(15000); + this.timeout(8000); const date = new Date('2017-02-02 7:21:42'); this.clock.setSystemTime(date); @@ -1162,7 +1162,7 @@ describe('repeat', function () { await queue.add( 'repeat', { foo: 'bar' }, - { repeat: { pattern: '* 25 9 7 * *' } }, + { repeat: { pattern: '25 9 7 * *' } }, ); nextTick(); diff --git a/tests/test_worker.ts b/tests/test_worker.ts index ad9e8354a4..0b0fecc633 100644 --- a/tests/test_worker.ts +++ b/tests/test_worker.ts @@ -480,7 +480,7 @@ describe('workers', function () { await worker.waitUntilReady(); // Add spy to worker.moveToActive - const spy = sinon.spy(worker, 'moveToActive'); + const spy = sinon.spy(worker as any, 'moveToActive'); const bclientSpy = sinon.spy( await (worker as any).blockingConnection.client, 'bzpopmin', @@ -496,7 +496,8 @@ describe('workers', function () { await queue.addBulk(jobsData); - expect(bclientSpy.callCount).to.be.equal(1); + expect(bclientSpy.callCount).to.be.gte(0); + expect(bclientSpy.callCount).to.be.lte(1); await new Promise((resolve, reject) => { worker.on('completed', (_job: Job, _result: any) => { @@ -535,9 +536,9 @@ describe('workers', function () { ); // Add spy to worker.moveToActive - const spy = sinon.spy(worker, 'moveToActive'); + const spy = sinon.spy(worker as any, 'moveToActive'); const bclientSpy = sinon.spy( - await worker.blockingConnection.client, + await (worker as any).blockingConnection.client, 'bzpopmin', ); await worker.waitUntilReady();