modify
This commit is contained in:
@@ -47,17 +47,22 @@ class OnWorkerStart extends Callback
|
|||||||
$runtime = file_get_contents(storage('runtime.php'));
|
$runtime = file_get_contents(storage('runtime.php'));
|
||||||
$annotation = Snowflake::app()->getAnnotation();
|
$annotation = Snowflake::app()->getAnnotation();
|
||||||
$annotation->setLoader(unserialize($runtime));
|
$annotation->setLoader(unserialize($runtime));
|
||||||
if ($isWorker === true) {
|
return (new Pipeline())
|
||||||
|
->if($isWorker, function ($annotation, $server) {
|
||||||
$annotation->runtime(CONTROLLER_PATH);
|
$annotation->runtime(CONTROLLER_PATH);
|
||||||
$annotation->runtime(APP_PATH, CONTROLLER_PATH);
|
$annotation->runtime(APP_PATH, CONTROLLER_PATH);
|
||||||
|
|
||||||
name($this->server->worker_pid, 'Worker.' . $this->server->worker_id);
|
name($server->worker_pid, 'Worker.' . $server->worker_id);
|
||||||
} else {
|
})
|
||||||
|
->else(function ($annotation, $server) {
|
||||||
$annotation->runtime(MODEL_PATH);
|
$annotation->runtime(MODEL_PATH);
|
||||||
|
|
||||||
name($this->server->worker_pid, 'Task.' . $this->server->worker_id);
|
name($server->worker_pid, 'Task.' . $server->worker_id);
|
||||||
}
|
})
|
||||||
return $annotation;
|
->catch(function (\Throwable $throwable) {
|
||||||
|
$this->addError($throwable->getMessage());
|
||||||
|
})
|
||||||
|
->exec($annotation, $this->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace HttpServer\Events;
|
||||||
|
|
||||||
|
|
||||||
|
class Pipeline
|
||||||
|
{
|
||||||
|
|
||||||
|
private \Closure $if;
|
||||||
|
private \Closure $else;
|
||||||
|
private \Closure $catch;
|
||||||
|
|
||||||
|
private bool $condition;
|
||||||
|
|
||||||
|
private \Throwable $throwable;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $condition
|
||||||
|
* @param \Closure $handler
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function if(bool $condition, \Closure $handler): static
|
||||||
|
{
|
||||||
|
$this->condition = $condition;
|
||||||
|
$this->if = $handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Closure $handler
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function else(\Closure $handler): static
|
||||||
|
{
|
||||||
|
$this->else = $handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Closure $handler
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function catch(\Closure $handler): static
|
||||||
|
{
|
||||||
|
$this->catch = $handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $argv
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function exec(...$argv)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if ($this->condition === false) {
|
||||||
|
call_user_func($this->else, ...$argv);
|
||||||
|
} else {
|
||||||
|
call_user_func($this->if, ...$argv);
|
||||||
|
}
|
||||||
|
return $argv;
|
||||||
|
} catch (\Throwable $exception) {
|
||||||
|
call_user_func($this->catch, $exception, ...$argv);
|
||||||
|
return $argv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user