|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Command\Queue; |
|
4
|
|
|
|
|
5
|
|
|
use Ronanchilvers\Foundation\Facade\Queue; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Command to watch a given queue for jobs |
|
14
|
|
|
* |
|
15
|
|
|
* @author Ronan Chilvers <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class WatchCommand extends Command |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @author Ronan Chilvers <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
public function configure() |
|
23
|
|
|
{ |
|
24
|
|
|
$this |
|
25
|
|
|
->setName('queue:watch') |
|
26
|
|
|
->setDescription('Watch a given queue for jobs') |
|
27
|
|
|
->addArgument( |
|
28
|
|
|
'queue', |
|
29
|
|
|
InputArgument::REQUIRED, |
|
30
|
|
|
'The queue to watch for jobs' |
|
31
|
|
|
) |
|
32
|
|
|
->addOption( |
|
33
|
|
|
'timeout', |
|
34
|
|
|
't', |
|
35
|
|
|
InputOption::VALUE_REQUIRED, |
|
36
|
|
|
'The timeout for reserving jobs', |
|
37
|
|
|
5 |
|
38
|
|
|
) |
|
39
|
|
|
->addOption( |
|
40
|
|
|
'iterations', |
|
41
|
|
|
'i', |
|
42
|
|
|
InputOption::VALUE_REQUIRED, |
|
43
|
|
|
'The maximum number of iterations', |
|
44
|
|
|
null |
|
45
|
|
|
) |
|
46
|
|
|
; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @author Ronan Chilvers <[email protected]> |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
53
|
|
|
{ |
|
54
|
|
|
$queue = $input->getArgument('queue'); |
|
55
|
|
|
$timeout = $input->getOption('timeout'); |
|
56
|
|
|
$iterations = $input->getOption('iterations'); |
|
57
|
|
|
|
|
58
|
|
|
$output->writeln('Starting watch...'); |
|
59
|
|
|
$output->writeln('Queue : ' . $queue); |
|
60
|
|
|
$output->writeln('Timeout : ' . $timeout); |
|
61
|
|
|
$output->writeln('Iterations : ' . ($iterations ?: 'unlimited')); |
|
62
|
|
|
Queue::watch( |
|
63
|
|
|
$queue, |
|
64
|
|
|
$timeout, |
|
65
|
|
|
$iterations, |
|
66
|
|
|
$output |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
return 0; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|