Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add more logging to shutdown and signal handler #870

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions classes/local/execution/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,25 @@ public function initialise() {
} catch (\Throwable $thrown) {
$this->abort($thrown);
}

// Register signal handler - if a signal caused the dataflow to stop.
\core_shutdown_manager::register_signal_handler(function ($signo){
$error = error_get_last();
$this->logger->log(Logger::NOTICE, 'Engine: shutdown signal ({signo}) received', [
'signo' => $signo,
'lasterror' => $error,
]);
return \core\local\cli\shutdown::signal_handler($signo);
});

// Register shutdown handler - if request is ended by client, abort and finalise flow.
\core_shutdown_manager::register_function(function (){
$this->logger->log(Logger::DEBUG, 'Engine: shutdown handler was called');

// If the script has stopped and flow is not finalised then abort.
if (!in_array($this->status, [self::STATUS_FINALISED, self::STATUS_ABORTED])) {
$error = error_get_last();
$this->logger->log(Logger::ERROR, 'Engine: shutdown happened abruptly', ['lasterror' => $error]);
$this->set_status(self::STATUS_ABORTED);
$this->run->finalise($this->status, $this->export());
}
Expand Down
Loading