Quantcast
Viewing all articles
Browse latest Browse all 37

Advanced queue module: How to stop processing queue in cron, when some conditions apply in job event/job preprocessing?

I have a custom module handling jobs from the Advanced Queue module.To limit the number of jobs allowed to be processed in one cron run, I have some configuration variables in my custom module. With an event listener my function gets called correctly, when the queue is processed.

How can I fetch the current running process of the queue and stop it?

public static function getSubscribedEvents() {  $events[AdvancedQueueEvents::PRE_PROCESS][] = ['checkLimits'];  return $events;}public function checkLimits(JobEvent $event) {  $job_type = $event->getJob()->getType();  if ($job_type === 'MYMODULE_send_reports') {    $config = \Drupal::configFactory()->getEditable('MYMODULE.settings');    if (!empty($config)) {      $number_of_max_emails_to_send_per_day  = $config->get('number_of_max_emails_to_send_per_day');      $number_of_max_emails_to_send_per_hour = $config->get('number_of_max_emails_to_send_per_hour');      $remaining_emails_day = $config->get('remaining_emails_day');      $remaining_emails_hour = $config->get('remaining_emails_hour');      if ($remaining_emails_day <= 0) {        $queue = Queue::load($event->getJob()->getQueueId());        // $processor_id is only a string like "cron".        $processor_id = $queue->getProcessor();      }    }  }}

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>