1818 */
1919abstract class AbstractWorker extends Task implements WorkerInterface
2020{
21+ /**
22+ * Started worker status
23+ *
24+ * @const string STATUS_STARTED
25+ */
26+ const STATUS_STARTED = 'started ' ;
27+
28+ /**
29+ * Exited worker status
30+ *
31+ * @const string STATUS_EXITED
32+ */
33+ const STATUS_EXITED = 'exited ' ;
34+
35+
2136 protected $ taskOptionBaseList = [
2237 'workflow: ' , // required step code config file
2338 '?force ' , // Optional force run even if lockfile exists
@@ -38,7 +53,6 @@ abstract class AbstractWorker extends Task implements WorkerInterface
3853
3954 protected $ workflowConfig ;
4055
41-
4256 /**
4357 * Inits the current worker according to the given workflow config
4458 * - Loads the config
@@ -111,6 +125,7 @@ public final function startAction(array $paramList)
111125 $ this ->lock ();
112126 $ this ->initWorker ();
113127
128+
114129 // xxx Factorize stdout/err support
115130 $ this ->getDI ()->get ('logr ' )->info (
116131 "Worker listening on \033[32m " .
@@ -147,7 +162,11 @@ public final function startAction(array $paramList)
147162 $ this ->processMonitoringMessage ($ msgDto );
148163 continue ;
149164 }
150- $ this ->processMessage ($ msgDto );
165+ try {
166+ $ this ->processMessage ($ msgDto );
167+ } catch (\Exception $ e ) {
168+ $ this ->getDI ()->get ('logger ' )->error ($ e ->getMessage ());
169+ }
151170 }
152171 }
153172
@@ -214,7 +233,6 @@ private function initMq()
214233
215234 // xxx put kafka\TopicConf in DI and config in a config file
216235 $ this ->kafkaTopicConf = new \RdKafka \TopicConf ();
217- $ this ->kafkaTopicConf ->set ('offset.store.method ' , 'file ' );
218236 $ this ->kafkaTopicConf ->set ('auto.commit.interval.ms ' , 100 );
219237 $ this ->kafkaTopicConf ->set ('offset.store.sync.interval.ms ' , 100 );
220238 $ this ->kafkaTopicConf ->set ('offset.store.method ' , 'broker ' );
@@ -263,13 +281,27 @@ private function getLockFilePath()
263281 {
264282 $ this ->getDI ()->get ('logr ' )->debug (json_encode (func_get_args ()));
265283 $ lockDirPath = '/var/run/ ' ;
284+ $ workerName = self ::getWorkerCode ($ this ->paramHash );
285+ $ lockFileName = $ workerName ;
286+ return $ lockDirPath . $ lockFileName . '.pid ' ;
287+ }
288+
289+ /**
290+ * Returns the code of the current worker according to the worker given argv
291+ *
292+ * @param array $paramHash The argv list
293+ *
294+ * @return string worker code e.g. : disturb-step-computesomething-1
295+ */
296+ public static function getWorkerCode (array $ paramHash )
297+ {
266298 $ taskFullName = get_called_class ();
267299 // xxx We will probably have to deal w/ the BU
268300 if (strpos ($ taskFullName , 'Manager ' )) {
269- $ lockFileName = 'disturb-manager ' ;
301+ $ workerName = 'disturb-manager ' ;
270302 } else {
271- $ lockFileName = 'disturb-step- ' . $ this -> paramHash ['step ' ] . '- ' . $ this -> paramHash ['workerId ' ];
303+ $ workerName = 'disturb-step- ' . $ paramHash ['step ' ] . '- ' . $ paramHash ['workerId ' ];
272304 }
273- return $ lockDirPath . $ lockFileName . ' .pid ' ;
305+ return $ workerName ;
274306 }
275307}
0 commit comments