This commit is contained in:
2021-03-01 15:54:11 +08:00
parent b859a582c7
commit b4388fd7d2
2 changed files with 23 additions and 28 deletions
+16 -14
View File
@@ -16,19 +16,21 @@ use Swoole\Server;
*/ */
class OnFinish extends Callback class OnFinish extends Callback
{ {
/** /**
* @param Server $server * @param Server $server
* @param $task_id * @param $task_id
* @param $data * @param $data
* @throws Exception * @throws Exception
*/ */
public function onHandler(Server $server, $task_id, $data) public function onHandler(Server $server, $task_id, $data)
{ {
try { try {
fire(Event::TASK_FINISH, [$task_id, $data]); fire(Event::TASK_FINISH, [$task_id, $data]);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->addError($exception, 'task'); $this->addError($exception, 'task');
} } finally {
} Snowflake::app()->decrement();
}
}
} }
+7 -14
View File
@@ -48,17 +48,13 @@ class OnTask extends Callback
*/ */
public function onTask(Server $server, int $task_id, int $from_id, string $data): mixed public function onTask(Server $server, int $task_id, int $from_id, string $data): mixed
{ {
$app = Snowflake::app()->increment(); Snowflake::app()->increment();
Coroutine\defer(function () use ($app) {
$app->decrement();
});
$time = microtime(TRUE);
if (empty($data)) { if (empty($data)) {
return $server->finish('null data'); return $server->finish('null data');
} }
$finish = $this->runTaskHandler($data); $time = microtime(TRUE);
$finish = $this->runTaskHandler($data);
if (!$finish) { if (!$finish) {
$finish = []; $finish = [];
} }
@@ -78,16 +74,13 @@ class OnTask extends Callback
*/ */
public function onContinueTask(Server $server, Server\Task $task): mixed public function onContinueTask(Server $server, Server\Task $task): mixed
{ {
$app = Snowflake::app()->increment(); Snowflake::app()->increment();
Coroutine\defer(function () use ($app) {
$app->decrement();
});
$time = microtime(TRUE);
if (empty($task->data)) { if (empty($task->data)) {
return $task->finish('null data'); return $task->finish('null data');
} }
$finish = $this->runTaskHandler($task->data);
$time = microtime(TRUE);
$finish = $this->runTaskHandler($task->data);
if (!$finish) { if (!$finish) {
$finish = []; $finish = [];
} }