title: laravel - Execute Job After Multiple Jobs End
body: <p>I am working on a project where user gives me some input, and then I process those inputs. This processing takes long time, so I am using queues, and I want to send mail to the user that their processed data is ready on my app. What I want to achieve is, put all these jobs into the queue, then process them, and when a user's all processing ends, to mail that user. </p>
  
  <p>I am using 2 phase queue. First, I get the input and dispatch a job where the input gets parsed and divided into sub-datasets, and dispatch another job from that job which processes the parsed input data from the first job. Why I did this is, the first job takes less time than the second job, and I want to use jobs to only do the processing, without any interruption or extra work with parsing, the first phase is all about parsing and the second part is all about processing. The processing part may fail and the queue will process it again if it fails, so if I do not divide the input into the sub-jobs, a fail near the end of the job may cause all the processing for the job to be done again.</p>
  
  <p>If I put all those jobs to the same queue, and assign that mailing job to the <code>Queue::after</code> method, a user may have to wait for all the queue to finish, if I understood correctly. I want to be able to send a mail to the user when all of his inputs have been processed, without waiting any other user's inputs to be processed. The documents for Laravel Queue shows an example method:</p>
  
  <pre><code>Queue::after(function (JobProcessed $event) {
      // $event-&gt;connectionName
      // $event-&gt;job
      // $event-&gt;job-&gt;payload()
  });
  </code></pre>
  
  <p>And what I understood from this is this works after every processed job, and I can access the job properties with the <code>$event</code> object. This is not going to work with my 2-phase queue structure. I know I can use some counters in database to check if all the processing is done, but I want to know if there is a better and more elegant way of achieving this.</p>
  
  <p>Thank you very much.</p>