eee
This commit is contained in:
@@ -6,6 +6,7 @@ use Kiri;
|
||||
use Kiri\Abstracts\CoordinatorManager;
|
||||
use Kiri\Coordinator;
|
||||
use Kiri\Core\Help;
|
||||
use Kiri\Di\Inject\Container;
|
||||
use Kiri\Events\EventDispatch;
|
||||
use Kiri\Server\Events\OnAfterWorkerStart;
|
||||
use Kiri\Server\Events\OnBeforeWorkerStart;
|
||||
@@ -28,6 +29,14 @@ use function config;
|
||||
class OnServerWorker extends Kiri\Server\Abstracts\Server
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var EventDispatch
|
||||
*/
|
||||
#[Container(EventDispatch::class)]
|
||||
public EventDispatch $dispatch;
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -62,16 +71,15 @@ class OnServerWorker extends Kiri\Server\Abstracts\Server
|
||||
*/
|
||||
public function onWorkerStart(Server $server, int $workerId): void
|
||||
{
|
||||
$dispatch = Kiri::getDi()->get(EventDispatch::class);
|
||||
$dispatch->dispatch(new OnBeforeWorkerStart($server, $workerId));
|
||||
$this->dispatch->dispatch(new OnBeforeWorkerStart($server, $workerId));
|
||||
if ($workerId < $server->setting['worker_num']) {
|
||||
CoordinatorManager::utility(Coordinator::WORKER_START)->waite();
|
||||
|
||||
$dispatch->dispatch(new OnWorkerStart($server, $workerId));
|
||||
$this->dispatch->dispatch(new OnWorkerStart($server, $workerId));
|
||||
} else {
|
||||
$dispatch->dispatch(new OnTaskerStart($server, $workerId));
|
||||
$this->dispatch->dispatch(new OnTaskerStart($server, $workerId));
|
||||
}
|
||||
$dispatch->dispatch(new OnAfterWorkerStart($server, $workerId));
|
||||
$this->dispatch->dispatch(new OnAfterWorkerStart($server, $workerId));
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +101,8 @@ class OnServerWorker extends Kiri\Server\Abstracts\Server
|
||||
*/
|
||||
public function onWorkerStop(Server $server, int $workerId): void
|
||||
{
|
||||
error(sprintf('Worker#%d::%d stop.',$server->worker_pid, $workerId));
|
||||
|
||||
event(new OnWorkerStop($server, $workerId));
|
||||
Timer::clearAll();
|
||||
}
|
||||
@@ -105,6 +115,8 @@ class OnServerWorker extends Kiri\Server\Abstracts\Server
|
||||
*/
|
||||
public function onWorkerExit(Server $server, int $workerId): void
|
||||
{
|
||||
error(sprintf('Worker#%d::%d exit.',$server->worker_pid, $workerId));
|
||||
|
||||
event(new OnWorkerExit($server, $workerId));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user