Skip to content

Commit

Permalink
Merge pull request #870 from catalyst/869-add-additional-logging-for-…
Browse files Browse the repository at this point in the history
…sudden-shutdowns

fix: add more logging to shutdown and signal handler
  • Loading branch information
keevan authored Feb 27, 2024
2 parents 7a83148 + 8ef7fa9 commit a75df4a
Showing 1 changed file with 15 additions and 0 deletions.
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

0 comments on commit a75df4a

Please sign in to comment.