1 | <?php |
||
25 | class ParallelExec extends BaseTask implements CommandInterface, PrintedInterface |
||
26 | { |
||
27 | use \Robo\Common\CommandReceiver; |
||
28 | |||
29 | /** |
||
30 | * @var Process[] |
||
31 | */ |
||
32 | protected $processes = []; |
||
33 | |||
34 | /** |
||
35 | * @var null|int |
||
36 | */ |
||
37 | protected $timeout = null; |
||
38 | |||
39 | /** |
||
40 | * @var null|int |
||
41 | */ |
||
42 | protected $idleTimeout = null; |
||
43 | |||
44 | /** |
||
45 | * @var null|int |
||
46 | */ |
||
47 | protected $waitInterval = 0; |
||
48 | |||
49 | /** |
||
50 | * @var bool |
||
51 | */ |
||
52 | protected $isPrinted = false; |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | public function getPrinted() |
||
58 | { |
||
59 | return $this->isPrinted; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param bool $isPrinted |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | public function printed($isPrinted = true) |
||
68 | { |
||
69 | $this->isPrinted = $isPrinted; |
||
70 | return $this; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string|\Robo\Contract\CommandInterface $command |
||
75 | * |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function process($command) |
||
79 | { |
||
80 | // TODO: Symfony 4 requires that we supply the working directory. |
||
81 | $this->processes[] = Process::fromShellCommandline($this->receiveCommand($command), getcwd()); |
||
82 | return $this; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Stops process if it runs longer then `$timeout` (seconds). |
||
87 | * |
||
88 | * @param int $timeout |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function timeout($timeout) |
||
93 | { |
||
94 | $this->timeout = $timeout; |
||
95 | return $this; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Stops process if it does not output for time longer then `$timeout` (seconds). |
||
100 | * |
||
101 | * @param int $idleTimeout |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | public function idleTimeout($idleTimeout) |
||
106 | { |
||
107 | $this->idleTimeout = $idleTimeout; |
||
108 | return $this; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Parallel processing will wait `$waitInterval` seconds after launching each process and before |
||
113 | * the next one. |
||
114 | * |
||
115 | * @param int $waitInterval |
||
116 | * |
||
117 | * @return $this |
||
118 | */ |
||
119 | public function waitInterval($waitInterval) |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function getCommand() |
||
129 | { |
||
132 | |||
133 | /** |
||
134 | * @return int |
||
135 | */ |
||
136 | public function progressIndicatorSteps() |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function run() |
||
200 | } |
||
201 |