Skip to content

Commit

Permalink
fix: add more logging to shutdown and signal handler
Browse files Browse the repository at this point in the history
Resolves #869
  • Loading branch information
keevan committed Feb 27, 2024
1 parent 7a83148 commit 7d2e603
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions classes/local/execution/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,22 @@ 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 7d2e603

Please sign in to comment.