modify
This commit is contained in:
@@ -40,25 +40,7 @@ class OnWorkerStart extends Callback
|
|||||||
$annotation = Snowflake::app()->getAnnotation();
|
$annotation = Snowflake::app()->getAnnotation();
|
||||||
$annotation->setLoader(unserialize($runtime));
|
$annotation->setLoader(unserialize($runtime));
|
||||||
|
|
||||||
putenv('state=start');
|
return $annotation;
|
||||||
putenv('worker=' . $this->server->worker_id);
|
|
||||||
|
|
||||||
$pipeLine = new Pipeline();
|
|
||||||
$pipeLine->if($isWorker, function ($annotation, $server) {
|
|
||||||
$annotation->runtime(CONTROLLER_PATH);
|
|
||||||
$annotation->runtime(APP_PATH, CONTROLLER_PATH);
|
|
||||||
|
|
||||||
name($server->worker_pid, 'Worker.' . $server->worker_id);
|
|
||||||
})
|
|
||||||
->else(function ($annotation, $server) {
|
|
||||||
$annotation->runtime(MODEL_PATH);
|
|
||||||
|
|
||||||
name($server->worker_pid, 'Task.' . $server->worker_id);
|
|
||||||
})
|
|
||||||
->catch(function (\Throwable $throwable) {
|
|
||||||
$this->addError($throwable->getMessage());
|
|
||||||
})
|
|
||||||
->exec($annotation, $this->server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,15 +53,27 @@ class OnWorkerStart extends Callback
|
|||||||
*/
|
*/
|
||||||
public function onHandler(Server $server, int $worker_id): void
|
public function onHandler(Server $server, int $worker_id): void
|
||||||
{
|
{
|
||||||
$this->server = $server;
|
$annotation = $this->injectLoader();
|
||||||
|
(new Pipeline())
|
||||||
$this->injectLoader($this->isWorker($worker_id));
|
->if($this->isWorker($worker_id), function ($annotation, $server, $worker_id) {
|
||||||
|
$annotation->runtime(CONTROLLER_PATH);
|
||||||
if ($worker_id < $server->setting['worker_num']) {
|
$annotation->runtime(APP_PATH, CONTROLLER_PATH);
|
||||||
$this->onWorker($server, $worker_id);
|
$this->onWorker($server, $server->worker_id);
|
||||||
} else {
|
name($server->worker_pid, 'Worker.' . $worker_id);
|
||||||
$this->onTask($server, $worker_id);
|
})
|
||||||
}
|
->else(function ($annotation, $server, $worker_id) {
|
||||||
|
$annotation->runtime(MODEL_PATH);
|
||||||
|
$this->onTask($server, $server->worker_id);
|
||||||
|
name($server->worker_pid, 'Task.' . $worker_id);
|
||||||
|
})
|
||||||
|
->catch(function (\Throwable $throwable) {
|
||||||
|
$this->addError($throwable->getMessage());
|
||||||
|
})
|
||||||
|
->before(function ($annotation, $server, $worker_id) {
|
||||||
|
putenv('state=start');
|
||||||
|
putenv('worker=' . $worker_id);
|
||||||
|
})
|
||||||
|
->exec($annotation, $server, $worker_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ class Pipeline
|
|||||||
private \Closure $_if;
|
private \Closure $_if;
|
||||||
private \Closure $_else;
|
private \Closure $_else;
|
||||||
private \Closure $_catch;
|
private \Closure $_catch;
|
||||||
|
private \Closure $_after;
|
||||||
|
private \Closure $_before;
|
||||||
|
|
||||||
private bool $condition;
|
private bool $condition;
|
||||||
|
|
||||||
@@ -48,6 +50,26 @@ class Pipeline
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Closure $handler
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function after(\Closure $handler): static
|
||||||
|
{
|
||||||
|
$this->_after = $handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Closure $handler
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function before(\Closure $handler): static
|
||||||
|
{
|
||||||
|
$this->_before = $handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $argv
|
* @param $argv
|
||||||
@@ -56,16 +78,18 @@ class Pipeline
|
|||||||
public function exec(...$argv)
|
public function exec(...$argv)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
call_user_func($this->_before, ...$argv);
|
||||||
if ($this->condition !== true) {
|
if ($this->condition !== true) {
|
||||||
call_user_func($this->_else, ...$argv);
|
call_user_func($this->_else, ...$argv);
|
||||||
} else {
|
} else {
|
||||||
call_user_func($this->_if, ...$argv);
|
call_user_func($this->_if, ...$argv);
|
||||||
}
|
}
|
||||||
var_dump(__METHOD__);
|
|
||||||
return $argv;
|
return $argv;
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
call_user_func($this->_catch, $exception);
|
call_user_func($this->_catch, $exception);
|
||||||
return $argv;
|
return $argv;
|
||||||
|
} finally {
|
||||||
|
call_user_func($this->_after, ...$argv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user