Skip to content
Snippets Groups Projects
Unverified Commit 01802010 authored by Daniel Kesselberg's avatar Daniel Kesselberg
Browse files

Make sure to catch php errors during job execution

parent 4765f5b3
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,7 @@ abstract class Job implements IJob { ...@@ -63,7 +63,7 @@ abstract class Job implements IJob {
$logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
$jobList->setExecutionTime($this, $timeTaken); $jobList->setExecutionTime($this, $timeTaken);
} catch (\Exception $e) { } catch (\Throwable $e) {
if ($logger) { if ($logger) {
$logger->logException($e, [ $logger->logException($e, [
'app' => 'core', 'app' => 'core',
......
...@@ -39,6 +39,27 @@ class JobTest extends \Test\TestCase { ...@@ -39,6 +39,27 @@ class JobTest extends \Test\TestCase {
$this->assertCount(1, $jobList->getAll()); $this->assertCount(1, $jobList->getAll());
} }
public function testRemoveAfterError() {
$jobList = new DummyJobList();
$job = new TestJob($this, function () {
$test = null;
$test->someMethod();
});
$jobList->add($job);
$logger = $this->getMockBuilder(ILogger::class)
->disableOriginalConstructor()
->getMock();
$logger->expects($this->once())
->method('logException')
->with($this->isInstanceOf(\Throwable::class));
$this->assertCount(1, $jobList->getAll());
$job->execute($jobList, $logger);
$this->assertTrue($this->run);
$this->assertCount(1, $jobList->getAll());
}
public function markRun() { public function markRun() {
$this->run = true; $this->run = true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment