Skip to content

Commit ec269cf

Browse files
committed
Update BackgroundJob.php
If an error happens during the command's execution, it will be silent. This makes sure it isn't silent, and that the output gets logged regardless. I ran into this issue trying to make PHP-DI work with Jobby (basically wanted to autowire my job classes to use dependencies defined by the app) and noticed the output is silent when it errors out, i.e. stuff like: ``` Argument 1 passed to Standard\Cron\ExampleCronTask::helloWorld() must be an instance of Psr\Log\LoggerInterface, none given, called in /home/vagrant/Code/nofw/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(210) : eval()'d code on line 3 ``` This type of message now gets logged to the error log as well, helping the debug process.
1 parent af51286 commit ec269cf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/BackgroundJob.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ protected function runFunction()
233233
$command = $this->getSerializer()->unserialize($this->config['closure']);
234234

235235
ob_start();
236-
$retval = $command();
236+
try {
237+
$retval = $command();
238+
} catch (\Throwable $e) {
239+
echo "Error! " . $e->getMessage() . "\n";
240+
}
237241
$content = ob_get_contents();
238242
if ($logfile = $this->getLogfile()) {
239243
file_put_contents($this->getLogfile(), $content, FILE_APPEND);

0 commit comments

Comments
 (0)