function drush_mob_queue_mob_exe_queue in Drush Queue Handling 8
Same name and namespace in other branches
- 7 mob_queue.drush.inc \drush_mob_queue_mob_exe_queue()
Run the queued job.
File
- ./
mob_queue.drush.inc, line 44 - Drush commands for Drush Queue Handling.
Code
function drush_mob_queue_mob_exe_queue($time = 900) {
// Allow execution to continue even if the request gets canceled.
@ignore_user_abort(TRUE);
if (!drush_get_option('no-reset-expired', FALSE)) {
// Reset expired items in the default queue implementation table.
$updated = \Drupal::database()
->update('queue')
->fields(array(
'expire' => 0,
))
->condition('expire', 0, '<>')
->condition('expire', \Drupal::time()
->getRequestTime(), '<')
->execute();
drush_log(dt('!updated expired items reset.', array(
'!updated' => $updated,
)));
}
// Force the current user to anonymous to ensure consistent permissions on
// cron runs.
$accountSwitcher = \Drupal::service('account_switcher');
$accountSwitcher
->switchTo(new Drupal\Core\Session\AnonymousUserSession());
// Try to allocate enough time to run all the hook_cron implementations.
Environment::setTimeLimit($time);
// Grab the defined cron queues.
//$queues = \Drupal::moduleHandler()->invokeAll('cron_queue_info');
$queues = \Drupal::service('mob_queue.operator')
->getQueueJobs();
\Drupal::moduleHandler()
->alter('mob_queue_cron_queue_info', $queues);
foreach ($queues as $queue_name => $info) {
// $this->queueFactory->get($queue_name)->createQueue();
}
reset($queues);
while (TRUE) {
// Due to backwards incompatible changes on array handling from PHP 5.x to
// 7.x, looping code must be kept simple. For instance, current item pointer
// should be advanced manually, since foreach() does not starting from 7.0.
// @see #2974823 for more info.
$queue_name = key($queues);
$info = current($queues);
if ($queue_name === NULL && $info === FALSE) {
break;
}
next($queues);
// Ensure the time is passed to the info variable.
$info['mob_queue']['time'] = $time;
// Allow other modules to alter the queues listing, order queue to process.
\Drupal::moduleHandler()
->alter('mob_queue_queue_processing', $queue_name, $info, $queues);
\Drupal::service('mob_queue.operator')
->processQueues($queue_name, $info);
\Drupal::moduleHandler()
->invokeAll('mob_queue_queue_processed', [
$queue_name,
$info,
$queues,
]);
}
// Restore the user.
$accountSwitcher
->switchBack();
}