title: Laravel Queues - Run multiple/batch jobs with transaction rollback on fail and commit on complete
body: <p>My scenario is in relation to a large order that needs to be cancelled.</p>
  
  <ul>
  <li>The order contains 200 different item lines i.e. orderItems.</li>
  <li>Each line of the order is cancelled and triggers a calculation of stock and subsequent movement of stock.</li>
  <li>When all order lines have been successfully, the order status can be updated to "cancelled".</li>
  </ul>
  
  <p>For a few lines of an order this operation can be done synchronously, no problem. When orders are large then the processing power required means that my best option it to split the process down into separate operations within a queue.</p>
  
  <p>i.e. </p>
  
  <p>Run job</p>
  
  <p>OrderController.php</p>
  
  <pre><code>CancelOrder::dispatch($order);
  </code></pre>
  
  <p>Jobs/CancelOrder.php handle()</p>
  
  <pre><code>$this-&gt;order-&gt;orderItems()-&gt;each(function(OrderItem $orderItem){
      CancelAndReallocateOrderItem::dispatch($orderItem, $this-&gt;user);
  });
  </code></pre>
  
  <p>Jobs/CancelAndReallocateOrderItem.php handle()</p>
  
  <pre><code>$this-&gt;orderItem-&gt;cancelAllocatedAndReservedStock();
  $this-&gt;orderItem-&gt;product-&gt;reAllocateOrderItems();
  </code></pre>
  
  <p>For this order with 200 lines, 200 instances of CancelAndReallocateOrderItem will be started, allowing the cancellation to process in a couple of minutes.</p>
  
  <p>I am now trying to work out if its possible to:</p>
  
  <ol>
  <li>If any of the child jobs throw an error, can I rollback the entire batch of transactions.</li>
  <li>When all child jobs have completed successfully, how can I run some some final code (i.e. send notification, change order status etc.)</li>
  </ol>