This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
DeployActionCommand.php
64 lines (53 loc) · 2.13 KB
/
DeployActionCommand.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
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Spy\TimelineBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* This command will deploy each actions (see limit option) which
* has PUBLISHED on status_wanted.
*
* @uses ContainerAwareCommand
* @author Stephane PY <py.stephane1@gmail.com>
*/
class DeployActionCommand extends ContainerAwareCommand
{
/**
* configure command
*/
protected function configure()
{
$this
->setName('spy_timeline:deploy')
->setDescription('Deploy on spreads for waiting action')
->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'How many actions will be deployed', 200);
}
/**
* @param InputInterface $input input variable
* @param OutputInterface $output output variable
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$limit = (int) $input->getOption('limit');
if ($limit < 1) {
throw new \InvalidArgumentException('Limit defined should be biggest than 0 ...');
}
$container = $this->getContainer();
$actionManager = $container->get('spy_timeline.action_manager');
$results = $actionManager->findActionsWithStatusWantedPublished($limit);
$output->writeln(sprintf('<info>There is %s action(s) to deploy</info>', count($results)));
$deployer = $container->get('spy_timeline.spread.deployer');
foreach ($results as $action) {
try {
$deployer->deploy($action, $actionManager);
$output->writeln(sprintf('<comment>Deploy action %s</comment>', $action->getId()));
} catch (\Exception $e) {
$message = sprintf('[TIMELINE] Error during deploy action %s', $action->getId());
$container->get('logger')->crit($message);
$output->writeln(sprintf('<error>%s</error>', $message));
}
}
$output->writeln('<info>Done</info>');
}
}