Skip to content

Commit

Permalink
fixed: 异常处理afterHandle调用处理
Browse files Browse the repository at this point in the history
  • Loading branch information
bingcool committed Apr 13, 2023
1 parent 90d4b17 commit 6c378d4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Core/Crontab/AbstractCronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function runCron(string $cronName, string $expression, ?callable $func =
call_user_func($func, $cronName, $expression);
} else {
$this->doCronTask($cron, $cronName);
$this->afterHandle();
}

if (!$this->isDefer()) {
Expand Down
16 changes: 11 additions & 5 deletions src/Core/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Swoolefy\Core;

use Swoolefy\Core\Coroutine\CoroutineManager;
use Swoolefy\Exception\SystemException;

/**
* Class EventController
Expand Down Expand Up @@ -188,6 +187,17 @@ public function isDefer()
return $this->isDefer;
}

/**
* afterHandle
*/
public function afterHandle()
{
// call after action
$this->_afterAction();
// callHooks
$this->callAfterEventHook();
}

/**
* end unset var
* @return bool|void
Expand All @@ -199,10 +209,6 @@ public function end()
}
// set End
$this->setEnd();
// call hook callable
static::_afterAction();
// callHooks
$this->callAfterEventHook();
// handle log
$this->handleLog();
// remove
Expand Down
3 changes: 3 additions & 0 deletions src/Core/ServiceDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function dispatch()
$serviceInstance->{$action}($this->params);
// after Call
$serviceInstance->_afterAction($action);
// call hook callable
Hook::callHook(Hook::HOOK_AFTER_REQUEST);

} else {
$this->errorHandle($class, $action, 'error500');
return false;
Expand Down
6 changes: 2 additions & 4 deletions src/Core/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public function bootstrap(mixed $payload)

/**
* run instance
* @param int $fd
* @param mixed $input
* @param int|null $fd
* @param mixed $payload
* @param array $extendData
* @return void
*/
Expand Down Expand Up @@ -283,8 +283,6 @@ protected function defer()
*/
public function end()
{
// call hook callable
Hook::callHook(Hook::HOOK_AFTER_REQUEST);
// log handle
$this->handleLog();
// remove
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Timer/Tick.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ protected static function tick(int $timeIntervalMs, \Closure|array $func, array
$tickTaskInstance = new TickController();
call_user_func($func, $params, $timerId);
}
// call after action
$tickTaskInstance->afterHandle();
} catch (\Throwable $throwable) {
BaseServer::catchException($throwable);
} finally {
Expand Down Expand Up @@ -181,6 +183,8 @@ protected static function after(int $timeIntervalMs, \Closure|array $func, array
$tickTaskInstance = new TickController;
call_user_func($func, $params, $timer_id);
}
// call after action
$tickTaskInstance->afterHandle();
} catch (\Throwable $throwable) {
BaseServer::catchException($throwable);
} finally {
Expand Down
5 changes: 4 additions & 1 deletion src/Http/HttpAppServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ public function onTask($server, $task_id, $from_worker_id, $data, $task = null)
$taskInstance->setFromWorkerId((int)$from_worker_id);
$task && $taskInstance->setTask($task);
$taskInstance->$action($taskData);
$taskInstance->afterHandle();

unset($callable, $extendData, $fd);

} catch (\Throwable $throwable) {
$taskInstance->end();
if(!$taskInstance->isDefer()) {
$taskInstance->end();
}
throw $throwable;
}
}
Expand Down

0 comments on commit 6c378d4

Please sign in to comment.