forked from BurdaMagazinOrg/module-dcx-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcx_integration.drush.inc
76 lines (64 loc) · 2.08 KB
/
dcx_integration.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* @file Contains the code to generate the custom drush commands.
*/
use Drupal\Core\Queue\RequeueException;
use Drupal\Core\Queue\SuspendQueueException;
/**
* Implements hook_drush_command().
*/
function dcx_integration_drush_command() {
$items = [];
$items['dcx-queue'] = [
'description' => 'Works on the dcx queue',
];
return $items;
}
/**
* Implements drush_{module}_{command}.
*/
function drush_dcx_integration_dcx_queue() {
$queueFactory = \Drupal::service('queue');
$queueManager = \Drupal::service('plugin.manager.queue_worker');
$dcxQueues = [
'dcx_article_archiver',
'dcx_media_usage_worker',
];
foreach ($queueManager->getDefinitions() as $queue_name => $info) {
if (!in_array($queue_name, $dcxQueues)) {
continue;
}
// !! Code copied from cron->processQueue() !!
if (isset($info['cron'])) {
// Make sure every queue exists. There is no harm in trying to recreate
// an existing queue.
$queueFactory->get($queue_name)->createQueue();
$queue_worker = $queueManager->createInstance($queue_name);
$end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15);
$queue = $queueFactory->get($queue_name);
while (time() < $end && ($item = $queue->claimItem())) {
try {
$queue_worker->processItem($item->data);
$queue->deleteItem($item);
}
catch (RequeueException $e) {
// The worker requested the task be immediately requeued.
$queue->releaseItem($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.
continue 2;
}
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);
}
}
}
}
}