Make nightly job kick of child jobs and wait until all are finished before completing #1966
-
Is there a way to make a job kick-off child jobs dynamically, wait for those child jobs to finish and only then make the parent job finish? I know there's flows, but for what I understand with flows you define the child jobs statically. What I am looking for is way to define a job that iterates over documents in a database and create child jobs for some of those documents in another queue. To give a bit more context:
How can I make the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @sbruinsje, looks like you may need to check our step jobs patterns https://docs.bullmq.io/patterns/process-step-jobs#waiting-children |
Beta Was this translation helpful? Give feedback.
-
Is this similar to what I'm looking for, too? #1986 |
Beta Was this translation helpful? Give feedback.
hi @sbruinsje, sorry for the delay. job.moveToWaitingChildren() method moves the job to waiting children only if there are no pending children, this is why this method returns a boolean, to know if we moved the parent job to waiting-children state. When it returns true, we must throw WaitingChildrenError to prevent calling moveToFinished script and get missing lock error as we already moved the job to another state (waiting-children) and we delete the lock, this is happening in this way because we only keep the lock when job is in active state. Having this in place, when moving the parent to waiting children, workers are not blocked and they can pick other jobs to be processed. As soon as…