Bull: Cannot mark a job as completed based on the job ID

Created on 17 Nov 2015  路  10Comments  路  Source: OptimalBits/bull

Seems this:

imageQueue.getJob(data.jobId).moveToCompleted()

where data.jobId is an id number (1 or 2 or 3 ..... etc) does not work and throws:

[TypeError: imageQueue.getJob(...).moveToCompleted is not a function]

and the output of imageQueue.getJob(ID) seems to be a promise if it matters

like so:

Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _progressHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined,
  _settledValue: undefined }
enhancement

Most helpful comment

To me this seems like a huge overlook in the library's functionality at the moment for many common use scenarios. We want to do process specific jobs and overall jobs that are mainly used for progress updates for the user. Obviously we need to mark overall jobs completed once all the process jobs are done. At least based on the documentation you can't adjust progress or mark the job done at the job level making this impossible with Bull.

@manast, could you please clarify what are the issues related to implementing this? I would guess you need to update multiple lists/hashes in Redis to mark the job completed and it's just not a simple boolean switch on the job specific key?

All 10 comments

So seems that indeed getJob(id) returns a promise, so to mark it as completed we have to do:

queue.getJob(id).then(function(job) {job.moveToCompleted()})

But when i do this seems the job gets into the completed list but also remains in the waiting one as well.

Also no event is being triggered when this happens (the completed event)

you are using private APIs so I am afraid that will not work. What are you trying to achieve?

Hey Manuel,

I go into detail on here: https://gitter.im/OptimalBits/bull

But i basically want to manually set a job ID as completed and by doing that i would expect that this action will trigger the appropriate event.

Also trying to understand why when i use job.moveToCompleted it still keeps the job in the waiting list while adding it to the completed set.

You should study the function Queue##processJob.
moveToCompleted is an private function and it will not work out of context. Marking a job as completed will require some careful though and it should be implemented in the Queue class.

I also need this API features for my use case, where I'm notified of job completion through a web hook. Apparently no one has a good solution for this.

I need this API just to have an ability to remove job by id without stopping the whole queue while restart node process.

To me this seems like a huge overlook in the library's functionality at the moment for many common use scenarios. We want to do process specific jobs and overall jobs that are mainly used for progress updates for the user. Obviously we need to mark overall jobs completed once all the process jobs are done. At least based on the documentation you can't adjust progress or mark the job done at the job level making this impossible with Bull.

@manast, could you please clarify what are the issues related to implementing this? I would guess you need to update multiple lists/hashes in Redis to mark the job completed and it's just not a simple boolean switch on the job specific key?

@zero- There is no reason why such a function could not be implemented, however is not completely trivial, you need to remove the job from all the possible states it may be in and then you also have to think if you need to respect the lock or not in this case. States are represented by having the job in different lists or zsets. You can see how the standard moveToFinished (completed or failed) works here: https://github.com/OptimalBits/bull/blob/v3.0.0/lib/commands/moveToFinished-3.lua
A moveToComplete that can be used at anytime would need to enhance that script by removing the job from any other list it may be into. The most difficult part is to handle the possible scenario where a job is currently being processed and suddenly you want to move it to completed, easiest would be to detect this case and not allow it at all of course (i.e., trying to get a lock on the job and if and only if it can be locked proceed with the operation).

I need this as well as I am using Bull for the same use case as https://github.com/OptimalBits/bull/issues/790

@0fork @alexbudin

Here is the doc describing how to do this: https://github.com/OptimalBits/bull/blob/master/PATTERNS.md#manually-fetching-jobs

@manast Probably time to close this ticket.

Was this page helpful?
0 / 5 - 0 ratings