Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bull
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 175
    • Issues 175
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 9
    • Merge requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OptimalBits
  • bull
  • Issues
  • #1950
Closed
Open
Issue created Jan 11, 2021 by Administrator@rootContributor

Killing processes

Created by: LeoRuspini

Description

Hi all, thanks for this great work. I been researching the killing of waiting and active jobs (#114, #1098 (closed), #812 (closed), #1432 (closed)). I see the need for a killing method and there is several suggested "solutions", however, none of them seems to work properly plus they involved a lot of extra code (connection to ioredis, broadcast, etc). So in same setup as #1432 (closed), after discard and moveToFailed in provider, the job is marked as failed but still kept in waiting ( job.isWaiting(): true, job.isFailed(): true). The current example covers how to kill a job from the local server that run the process. However, the jobPromise.cancel() (described in the docs) seems to be removed and I can't find a method to remove from waiting state. If these two methods would be available, then all this can be added as a one line .kill(jobId) method (from the provider), which, from my point of view, is needed by many users.

Minimal, Working Test code to reproduce the issue.

(An easy to reproduce test case will dramatically decrease the resolution time.)

provider.js

let job = await queue.getJob(8)

job.discard();
job.moveToFailed(new Error('cancelled'), true)
// the two lines above should be replaced by a kill(jobId) method

worker.js

queue.process(Job', 2, __dirname + '/job.js')

queue.on('active', async (job, jobPromise) => {
    console.log("Worker: Active ", job.id)
    var idx = setInterval(async () => {
        isActive = await job.isActive()
        isCompleted = await job.isCompleted()
        isFailed = await job.isFailed()
        console.log("Worker: Checking job ", job.id, isActive, isCompleted, isFailed)
        if (isActive && (isCompleted || isFailed)) {
            console.log("Should kill job", job.id)
            // jobPromise.cancel()
        }
        if (!isActive) {
            console.log("Leaving interval", job.id)
            return clearInterval(idx)
        }
    }, 500)
})

queue.on('global:failed', async (jobId) => {
    console.log("Worker: Job ", jobId, " got globally failed ")
    // Remove ??
    queue.getJob(jobId)
        .then(async (job) => {
            console.log("Worker: Should I remove locally Job ", job.id)
            let waiting = await job.isWaiting()
            console.log("Worker: Job", job.id, waiting, failed)
            if(waiting){
                console.log("Should remove from waiting job", job.id)
                // job.removeWaiting()
            }
        })
        .catch((e) => {
            console.log("Worker:Not able to get job", jobId, e)
        })
})

queue.process(1, __dirname + "/" + 'process.js')

Bull version

3.20.0

Additional information

Thanks a lot !!!

Assignee
Assign to
Time tracking