diff --git a/Abstracts/StatusEnum.php b/Abstracts/StatusEnum.php new file mode 100644 index 0000000..6b50be1 --- /dev/null +++ b/Abstracts/StatusEnum.php @@ -0,0 +1,12 @@ +dispatch->dispatch(new OnBeforeWorkerStart($workerId)); set_env('environmental_workerId', $workerId); + $this->status->setEnum(StatusEnum::START); if ($workerId < $server->setting['worker_num']) { $this->dispatch->dispatch(new OnWorkerStart($server, $workerId)); } else { @@ -70,6 +75,8 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server */ public function onWorkerStop(Server $server, int $workerId) { + $this->status->setEnum(StatusEnum::STOP); + $this->dispatch->dispatch(new OnWorkerStop($server, $workerId)); } @@ -82,6 +89,8 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server */ public function onWorkerExit(Server $server, int $workerId) { + $this->status->setEnum(StatusEnum::EXIT); + $this->dispatch->dispatch(new OnWorkerExit($server, $workerId)); } @@ -98,6 +107,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server */ public function onWorkerError(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal) { + $this->status->setEnum(StatusEnum::ERROR); $this->dispatch->dispatch(new OnWorkerError($server, $worker_id, $worker_pid, $exit_code, $signal)); $message = sprintf('Worker#%d::%d error stop. signal %d, exit_code %d, msg %s', diff --git a/WorkerStatus.php b/WorkerStatus.php new file mode 100644 index 0000000..13957de --- /dev/null +++ b/WorkerStatus.php @@ -0,0 +1,33 @@ +enum = $enum; + } + + + /** + * @param StatusEnum $enum + * @return bool + */ + public function is(StatusEnum $enum): bool + { + return $this->enum == $enum; + } + + +}