|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Commander project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Daniel Schröder <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace GravityMedia\Commander\Console\Command; |
|
9
|
|
|
|
|
10
|
|
|
use GravityMedia\Commander\Commander; |
|
11
|
|
|
use GravityMedia\Commander\Process\OutputCallback; |
|
12
|
|
|
use GravityMedia\Commander\TaskManager; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\Process\Process; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Run command class. |
|
19
|
|
|
* |
|
20
|
|
|
* @package GravityMedia\Commander\Console\Command |
|
21
|
|
|
*/ |
|
22
|
|
|
class RunCommand extends Command |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function configure() |
|
28
|
|
|
{ |
|
29
|
|
|
parent::configure(); |
|
30
|
|
|
|
|
31
|
|
|
$this |
|
32
|
|
|
->setName('tasks:run') |
|
33
|
|
|
->setDescription('Run tasks'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
40
|
|
|
{ |
|
41
|
|
|
$config = $this->getCommanderConfig(); |
|
42
|
|
|
$commander = new Commander($config); |
|
43
|
|
|
if (!$commander->isSchemaValid()) { |
|
44
|
|
|
$commander->updateSchema(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$entityManager = $commander->getEntityManager(); |
|
48
|
|
|
$taskManager = new TaskManager($entityManager); |
|
49
|
|
|
$outputCallback = new OutputCallback($output, $commander->getLogger()); |
|
50
|
|
|
|
|
51
|
|
|
while (null !== $task = $taskManager->findNextTask(['pid' => null])) { |
|
52
|
|
|
$process = new Process($task->getEntity()->getScript()); |
|
53
|
|
|
$process->setTimeout($config->getCommandTimeout()); |
|
54
|
|
|
$process->start(); |
|
55
|
|
|
|
|
56
|
|
|
$task->updatePid($process->getPid()); |
|
57
|
|
|
$process->wait($outputCallback); |
|
58
|
|
|
$task->updateExitCode($process->getExitCode()); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|