Marking A Batch As Complete When The Jobs Fire Jobs?
- We want the user to start a process that splits about 10,000 tasks down into batches to mark them as finalized.
- We want to notify the user when all of those 10,000 tasks are fully processed....
- BUT each of those batches may have tasks within it that ALSO need to run sub-jobs before each item can be marked as finalized - for example, when we mark a task as finalized, we'd need to loop through each of its subtasks to mark them as finalized, and a task might - might - have so many subtasks that we need to split that off into jobs.
- There's not an easy way of knowing which tasks have how many subtasks until we get to that batch and dig deeper into whatever each task is.
- BUT we only want to notify the user when both all the jobs processing the tasks and all the jobs processing the subtasks have finished.
(NOTE: This isn't tasks per se, it's just the easiest way to give an analog to our sometimes arcane business logic. Yes, if it was purely tasks, it'd be smarter to mark the subtasks first and then mark the task as completed, but a) it's not actually tasks, and b) we don't have that option.)
Under simpler circumstances, I'd just use a Bus::batch to fire off a bunch of jobs, then use the ->then() function to fire off a "Processing Completed" event when it's done.
But if I fire off a bunch of jobs in the middle of a job, it doesn't normally wait until those sub-jobs are processed - it just fires off the jobs (or dispatches an event where a downstream handler handles the jobs, which is essentially the same thing) and marks the root job as complete. Which means the user gets notified when all the jobs marking tasks have finished, but before the jobs processing the subtasks have finished.
If you have jobs that need to trigger other jobs, how do you trigger a user when all the sub-jobs are also completed?
(Currently pondering maybe using dispatchSync instead of dispatch to bump those sub-jobs up in the queue, but that seems an inelegant and possibly an incorrect solution.)
Please or to participate in this conversation.