1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of HeriJobQueueBundle. |
5
|
|
|
* |
6
|
|
|
* (c) Alexandre Mogère |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Heri\Bundle\JobQueueBundle\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
class QueueCreateCommand extends ContainerAwareCommand |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
protected function configure() |
26
|
|
|
{ |
27
|
|
|
$this |
28
|
|
|
->setName('jobqueue:create') |
29
|
|
|
->setDescription('Create a queue') |
30
|
|
|
->addArgument('queue-name', InputArgument::REQUIRED, 'Which name do you want for the queue?') |
31
|
|
|
->addOption('timeout', null, InputOption::VALUE_OPTIONAL, 'Timeout') |
32
|
|
|
; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
39
|
|
|
{ |
40
|
|
|
$queue = $this->getContainer()->get('jobqueue'); |
41
|
|
|
|
42
|
|
|
$timeout = $input->getOption('timeout'); |
43
|
|
|
$name = $input->getArgument('queue-name'); |
44
|
|
|
|
45
|
|
|
$dialog = $this->getHelper('question'); |
46
|
|
|
if (!$timeout) { |
47
|
|
|
$timeout = $dialog->ask( |
48
|
|
|
$output, |
49
|
|
|
'<question>Please enter the timeout</question> [<comment>90</comment>]: ', |
50
|
|
|
90 |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($queue->create($name, $timeout)) { |
55
|
|
|
$action = 'created'; |
56
|
|
|
} else { |
57
|
|
|
$action = 'updated'; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$output->writeLn(sprintf('<info>Queue "%s" %s</info>', $name, $action)); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|