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

[Bug]: Removing and upserting a Job Scheduler in close succession does not create a new delayed job #3063

Open
1 task done
mbakiev opened this issue Feb 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@mbakiev
Copy link

mbakiev commented Feb 8, 2025

Version

v5.40.2

Platform

NodeJS

What happened?

When a Job Scheduler is removed with Queue.removeJobScheduler() and upserted again with Queue.upsertJobScheduler(), no new delayed task is created and the scheduled tasks never run.

Seems like during the upsert, it sees that there is a job with the expected id (based on milis?) that exist already and it doesn't not create a new task. But that task is in 'completed' state already, so it will never run again.

In the example below, we see the next: 1738974600000 in the Job Scheduler, and a task with id: 'repeat:test:1738974600000' already existing.

I've also seen some other strange behavior with Job Schedulers that is harder to reproduce and report. Sometimes the delayed task will not run, and it's scheduled execution time is well in the past.

How to reproduce.

const queue = new Queue('queue')

await queue.upsertJobScheduler('test', { every: 3 * 60 * 1000 }, { name: 'test-job', data: { foo: 'bar' } })

// A while later

// Deletes currently delayed 'test-job' job
await queue.removeJobScheduler('test')

// Does not create the new 'test-job'
await queue.upsertJobScheduler('test', { every: 3 * 60 * 1000 }, { name: 'test-job', data: { foo: 'bar' } })

const schedulers = await queue.getJobSchedulers()
const delayed = await queue.getDelayed()
const completed = await queue.getCompleted()

console.log({schedulers, delayed, completed})

Relevant log output

{
        schedulers: [
        {
            key: 'test',
            name: 'test-job',
            endDate: null,
            tz: null,
            pattern: null,
            every: '1800000',
            template: [Object],
            next: 1738974600000
        }
        ],
        delayed: [],
        completed: [
        Job {
            queue: [Queue],
            name: 'test-job',
            data: [Object],
            opts: [Object],
            id: 'repeat:test:1738975500000',
            progress: 0,
            returnvalue: null,
            stacktrace: [],
            delay: 0,
            priority: 0,
            attemptsStarted: 1,
            attemptsMade: 1,
            repeatJobKey: 'test',
            timestamp: 1738975641682,
            parentKey: undefined,
            parent: undefined,
            debounceId: undefined,
            deduplicationId: undefined,
            toKey: [Function: bound ],
            scripts: [Scripts],
            queueQualifiedName: 'bull:queue',
            finishedOn: 1738975643099,
            processedOn: 1738975641685,
            failedReason: undefined,
            nextRepeatableJobId: 'repeat:test:1738975680000'
        },
        Job {
            queue: [Queue],
            name: 'test-job',
            data: [Object],
            opts: [Object],
            id: 'repeat:test:1738974600000',
            progress: 0,
            returnvalue: null,
            stacktrace: [],
            delay: 0,
            priority: 0,
            attemptsStarted: 1,
            attemptsMade: 1,
            repeatJobKey: 'test',
            timestamp: 1738974891613,
            parentKey: undefined,
            parent: undefined,
            debounceId: undefined,
            deduplicationId: undefined,
            toKey: [Function: bound ],
            scripts: [Scripts],
            queueQualifiedName: 'bull:queue',
            finishedOn: 1738974892974,
            processedOn: 1738974891614,
            failedReason: undefined,
            nextRepeatableJobId: 'repeat:test:1738976400000'
        },
        . . .
        Job {
            queue: [Queue],
            name: 'test-job',
            data: [Object],
            opts: [Object],
            id: 'repeat:test:1738972800000',
            progress: 0,
            returnvalue: null,
            stacktrace: [],
            delay: 0,
            priority: 0,
            attemptsStarted: 1,
            attemptsMade: 1,
            repeatJobKey: 'test',
            timestamp: 1738973961543,
            parentKey: undefined,
            parent: undefined,
            debounceId: undefined,
            deduplicationId: undefined,
            toKey: [Function: bound ],
            scripts: [Scripts],
            queueQualifiedName: 'bull:queue',
            finishedOn: 1738973973988,
            processedOn: 1738973972090,
            failedReason: undefined,
            nextRepeatableJobId: 'repeat:test:1738974600000'
        }
        ]
    }

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mbakiev mbakiev added the bug Something isn't working label Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant