public static function SmartlingTranslatorUi::step in TMGMT Translator Smartling 8.3
Same name and namespace in other branches
- 8.4 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi::step()
- 8.2 src/SmartlingTranslatorUi.php \Drupal\tmgmt_smartling\SmartlingTranslatorUi::step()
Batch step definition to process one queue item.
Based on \Drupal\Core\Cron::processQueues().
File
- src/
SmartlingTranslatorUi.php, line 404 - Contains \Drupal\tmgmt_smartling\SmartlingTranslatorUi.
Class
- SmartlingTranslatorUi
- Smartling translator UI.
Namespace
Drupal\tmgmt_smartlingCode
public static function step($queue_name, $context) {
if (isset($context['interrupted']) && $context['interrupted']) {
return;
}
$queue_manager = \Drupal::service('plugin.manager.queue_worker');
$queue_factory = \Drupal::service('queue');
$info = $queue_manager
->getDefinition($queue_name);
$title = $info['title'];
// Make sure every queue exists. There is no harm in trying to recreate
// an existing queue.
$queue_factory
->get($queue_name)
->createQueue();
$queue_worker = $queue_manager
->createInstance($queue_name);
$queue = $queue_factory
->get($queue_name);
if ($item = $queue
->claimItem()) {
try {
$queue_worker
->processItem($item->data);
$context['message'] = $title;
$queue
->deleteItem($item);
} catch (SuspendQueueException $e) {
// If the worker indicates there is a problem with the whole queue,
// release the item and skip to the next queue.
$queue
->releaseItem($item);
watchdog_exception('cron', $e);
// Skip to the next queue.
$context['interrupted'] = TRUE;
} catch (Exception $e) {
// In case of any other kind of exception, log it and leave the item
// in the queue to be processed again later.
watchdog_exception('cron', $e);
}
}
}