This commit is contained in:
2021-04-15 21:16:48 +08:00
parent 52998e912c
commit e9243de9c1
+33 -18
View File
@@ -207,6 +207,39 @@ abstract class Crontab extends BaseObject
* @throws Exception
*/
public function execute(): void
{
\Swoole\Coroutine\go(function ($application) {
$application->isRecover($application);
}, $this);
$this->run();
}
/**
* @param $application
* @throws Exception
*/
public function isRecover($application)
{
try {
if ($application->isExit()) {
return;
}
if ($application->isMaxExecute()) {
call_user_func([$application, 'max_execute'], ...$application->params);
} else {
$application->recover();
}
} catch (\Throwable $throwable) {
logger()->addError($throwable, 'throwable');
}
}
/**
* @throws Exception
*/
private function run()
{
try {
$redis = Snowflake::app()->getRedis();
@@ -227,8 +260,6 @@ abstract class Crontab extends BaseObject
]));
} catch (\Throwable $throwable) {
logger()->addError($throwable, 'throwable');
} finally {
$this->after();
}
}
@@ -260,20 +291,4 @@ abstract class Crontab extends BaseObject
}
/**
* @throws Exception
*/
private function after(): void
{
if ($this->isExit()) {
return;
}
if ($this->isMaxExecute()) {
call_user_func([$this, 'max_execute'], ...$this->params);
} else {
$this->recover();
}
}
}