Skip to content

Add placeholder for queue hooks

eileen requested to merge queue into master

Note I have a code example for the listener - but we don't have a place for them

in config

  $dispatcher->addListener('civi.queue.isActive', [Queue::class, 'isSiteBusy']);

The function


  /**
   *
   * @throws \CRM_Core_Exception
   */
  public static function isSiteBusy($event): void {
    $threshold = (int) \CRM_Utils_Constant::value('busy_threshold', 500);
    if (!$threshold) {
      return;
    }
    $thresholdNumberOfMinutes = (int) \CRM_Utils_Constant::value('busy_threshold_minutes', 5);
    $countOfContributionsInTimeFrame = \CRM_Core_DAO::singleValueQuery(
      'SELECT COUNT(*) FROM log_civicrm_contribution WHERE log_date > DATE_SUB(NOW(), INTERVAL %1 MINUTE)',
      [1 => [$thresholdNumberOfMinutes, 'Integer']]
    );
    if ($countOfContributionsInTimeFrame > $threshold) {
      \Civi::log('wmf')->info(
        "Early return as queue is backed up. $countOfContributionsInTimeFrame contributions in the last $numberOfMinutes"
        . " minutes is greater than the threshold of $threshold"
      );
      $event->status = 'busy';
    }
  }
Edited by eileen

Merge request reports