1 | <?php |
||
22 | class ParallelExecutor implements ExecutorInterface |
||
23 | { |
||
24 | /** |
||
25 | * Try to start server on this port. |
||
26 | */ |
||
27 | const START_PORT = 3333; |
||
28 | |||
29 | /** |
||
30 | * If fails on start port, try until stop port. |
||
31 | */ |
||
32 | const STOP_PORT = 3340; |
||
33 | |||
34 | /** |
||
35 | * @var InputDefinition |
||
36 | */ |
||
37 | private $userDefinition; |
||
38 | |||
39 | /** |
||
40 | * @var \Deployer\Task\Task[] |
||
41 | */ |
||
42 | private $tasks; |
||
43 | |||
44 | /** |
||
45 | * @var \Deployer\Server\ServerInterface[] |
||
46 | */ |
||
47 | private $servers; |
||
48 | |||
49 | /** |
||
50 | * @var \Deployer\Server\Environment[] |
||
51 | */ |
||
52 | private $environments; |
||
53 | |||
54 | /** |
||
55 | * @var \Symfony\Component\Console\Input\InputInterface |
||
56 | */ |
||
57 | private $input; |
||
58 | |||
59 | /** |
||
60 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
61 | */ |
||
62 | private $output; |
||
63 | |||
64 | /** |
||
65 | * @var Informer |
||
66 | */ |
||
67 | private $informer; |
||
68 | |||
69 | /** |
||
70 | * @var int |
||
71 | */ |
||
72 | private $port; |
||
73 | |||
74 | /** |
||
75 | * @var Server |
||
76 | */ |
||
77 | private $pure; |
||
78 | |||
79 | /** |
||
80 | * @var \React\EventLoop\LoopInterface |
||
81 | */ |
||
82 | private $loop; |
||
83 | |||
84 | /** |
||
85 | * Wait until all workers finish they tasks. When set this variable to true and send new tasks to workers. |
||
86 | * |
||
87 | * @var bool |
||
88 | */ |
||
89 | private $wait = false; |
||
90 | |||
91 | /** |
||
92 | * @var QueueStorage |
||
93 | */ |
||
94 | private $outputStorage; |
||
95 | |||
96 | /** |
||
97 | * @var QueueStorage |
||
98 | */ |
||
99 | private $exceptionStorage; |
||
100 | |||
101 | /** |
||
102 | * Array will contain tasks list what workers has to before moving to next task. |
||
103 | * |
||
104 | * @var array |
||
105 | */ |
||
106 | private $tasksToDo = []; |
||
107 | |||
108 | /** |
||
109 | * Check if current task was successfully finished on all server (no exception was triggered). |
||
110 | * |
||
111 | * @var bool |
||
112 | */ |
||
113 | private $isSuccessfullyFinished = true; |
||
114 | |||
115 | /** |
||
116 | * Check if current task triggered a non-fatal exception. |
||
117 | * |
||
118 | * @var bool |
||
119 | */ |
||
120 | private $hasNonFatalException = false; |
||
121 | |||
122 | /** |
||
123 | * @var string |
||
124 | */ |
||
125 | 2 | private $lastExceptionMessage = false; |
|
126 | |||
127 | 2 | /** |
|
128 | 2 | * @var Local |
|
129 | */ |
||
130 | private $localhost; |
||
131 | |||
132 | /** |
||
133 | 2 | * @var Environment |
|
134 | */ |
||
135 | 2 | private $localEnv; |
|
136 | 2 | ||
137 | 2 | /** |
|
138 | 2 | * @param InputDefinition $userDefinition |
|
139 | 2 | */ |
|
140 | 2 | public function __construct(InputDefinition $userDefinition) |
|
144 | |||
145 | 2 | /** |
|
146 | 2 | * {@inheritdoc} |
|
147 | */ |
||
148 | public function run($tasks, $servers, $environments, $input, $output) |
||
198 | |||
199 | /** |
||
200 | 2 | * Start workers, put master port, server name to run on, and options stuff. |
|
201 | 2 | */ |
|
202 | 2 | public function startWorkers() |
|
246 | |||
247 | /** |
||
248 | * Wait for output from workers. |
||
249 | */ |
||
250 | public function catchOutput() |
||
265 | |||
266 | /** |
||
267 | * Wait for exceptions from workers. |
||
268 | */ |
||
269 | 2 | public function catchExceptions() |
|
300 | |||
301 | 1 | /** |
|
302 | 1 | * Action time for master! Send tasks `to-do` for workers and go to sleep. |
|
303 | 1 | * Also decide when to stop server/loop. |
|
304 | 2 | */ |
|
305 | public function sendTasks() |
||
346 | 2 | ||
347 | 2 | /** |
|
348 | 2 | * While idle master, print information about finished tasks. |
|
349 | 2 | */ |
|
350 | public function idle() |
||
380 | } |
||
381 |