/
BatchProcessTaskRunnerHandler.php
53 lines (44 loc) · 1.8 KB
/
BatchProcessTaskRunnerHandler.php
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
<?php
namespace Concrete\Core\Command\Task\Runner;
use Concrete\Core\Command\Batch\Stamp\BatchStamp;
use Concrete\Core\Command\Process\Command\ProcessMessageInterface;
use Concrete\Core\Command\Process\ProcessFactory;
use Concrete\Core\Command\Process\ProcessUpdater;
use Concrete\Core\Command\Task\Output\OutputInterface;
use Concrete\Core\Command\Task\Runner\Context\ContextInterface;
use Concrete\Core\Command\Task\Stamp\OutputStamp;
use Concrete\Core\Command\Task\TaskService;
defined('C5_EXECUTE') or die("Access Denied.");
class BatchProcessTaskRunnerHandler extends ProcessTaskRunnerHandler
{
/**
* @var ProcessUpdater
*/
protected $processUpdater;
public function __construct(ProcessUpdater $processUpdater, TaskService $taskService, ProcessFactory $processFactory)
{
$this->processUpdater = $processUpdater;
parent::__construct($taskService, $processFactory);
}
/**
* @param BatchProcessTaskRunner $runner
*/
public function run(TaskRunnerInterface $runner, ContextInterface $context)
{
$batch = $runner->getBatch();
$process = $runner->getProcess();
$batchEntity = $this->processFactory->createBatchEntity($batch);
$process->setBatch($batchEntity);
$messages = $batch->getWrappedMessages($batchEntity);
$total = count($messages);
$this->processFactory->setBatchTotal($batchEntity, $process, $total);
if ($total > 0) {
foreach ($messages as $message) {
$context->dispatchCommand($message, [new BatchStamp($batchEntity->getId())]);
}
} else {
// There were no actual messages in this batch – so let's close it
$this->processUpdater->closeProcess($process, ProcessMessageInterface::EXIT_CODE_SUCCESS);
}
}
}