This commit is contained in:
2021-04-15 20:09:52 +08:00
parent 5b70194b15
commit bd7b3b5edd
2 changed files with 19 additions and 29 deletions
+6 -11
View File
@@ -27,17 +27,12 @@ class OnPipeMessage extends Callback
public function onHandler(Server $server, int $src_worker_id, $swollen_universalize)
{
go(function () use ($server, $src_worker_id, $swollen_universalize) {
try {
match ($swollen_universalize['action'] ?? null) {
'kafka' => $this->onKafkaWorker($swollen_universalize),
'crontab' => $this->onCrontabWorker($swollen_universalize),
default => $this->onMessageWorker($server, $src_worker_id, $swollen_universalize)
};
} catch (\Throwable $exception) {
$this->addError($exception);
} finally {
fire(Event::SYSTEM_RESOURCE_RELEASES);
}
match ($swollen_universalize['action'] ?? null) {
'kafka' => $this->onKafkaWorker($swollen_universalize),
'crontab' => $this->onCrontabWorker($swollen_universalize),
default => $this->onMessageWorker($server, $src_worker_id, $swollen_universalize)
};
fire(Event::SYSTEM_RESOURCE_RELEASES);
});
}
+13 -18
View File
@@ -204,28 +204,23 @@ abstract class Crontab extends BaseObject
*/
public function execute(): void
{
try {
$redis = Snowflake::app()->getRedis();
$redis = Snowflake::app()->getRedis();
$name_md5 = $this->getName();
$name_md5 = $this->getName();
$redis->hSet(self::WAIT_END, $name_md5, serialize($this));
$redis->hSet(self::WAIT_END, $name_md5, serialize($this));
$params = call_user_func([$this, 'process'], ...$this->params);
$redis->hDel(self::WAIT_END, $name_md5);
if ($params === null) {
return;
}
$name = date('Y-m-d.log');
write(storage($name, '/log/crontab'), Json::encode([
'name' => $this->name,
'response' => serialize($params)
]));
} catch (\Throwable $throwable) {
logger()->addError($throwable, 'throwable');
} finally {
$this->after();
$params = call_user_func([$this, 'process'], ...$this->params);
$redis->hDel(self::WAIT_END, $name_md5);
if ($params === null) {
return;
}
$name = date('Y-m-d.log');
write(storage($name, '/log/crontab'), Json::encode([
'name' => $this->name,
'response' => serialize($params)
]));
$this->after();
}