• totten's avatar
    Queue - When UserJob.queue_id works down to zero tasks, update status and fire hook · 677170bd
    totten authored
    Suppose you setup a queue with several tasks and then run them all. What happens
    to the queue's status?
    
    Before
    ------
    
    The status always remains `active`.
    
    After
    -----
    
    Depends on the use-case:
    
    * If you have an open-ended queue providing an on-going service (no `UserJob`),
      then the status remains `active`.
    * If you have a fixed-purpose queue attached to a `UserJob`, then the status
      changes from `active` to `completed`, and it fires an event:
        ```
        function hook_civicrm_queueStatus(CRM_Queue_Queue $queue, string $status)
        ```
    
    Technical Details
    -----------------
    
    * There are two main ways that items get removed from a queue (`Queue.runNext`
      API and `civicrm/queue/ajax/runNext`).  Both of these fire an internal event
      (`civi.queue.check`) to consult the status.
    677170bd