Browse Source
Make sure to catch php errors during job execution
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
pull/19241/head
Daniel Kesselberg
6 years ago
No known key found for this signature in database
GPG Key ID: 36E3664E099D0614
2 changed files with
22 additions and
1 deletions
-
lib/private/BackgroundJob/Job.php
-
tests/lib/BackgroundJob/JobTest.php
|
|
|
@ -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']); |
|
|
|
$jobList->setExecutionTime($this, $timeTaken); |
|
|
|
} catch (\Exception $e) { |
|
|
|
} catch (\Throwable $e) { |
|
|
|
if ($logger) { |
|
|
|
$logger->logException($e, [ |
|
|
|
'app' => 'core', |
|
|
|
|
|
|
|
@ -39,6 +39,27 @@ class JobTest extends \Test\TestCase { |
|
|
|
$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() { |
|
|
|
$this->run = true; |
|
|
|
} |
|
|
|
|