diff --git a/src/Services/QueuedJobHandler.php b/src/Services/QueuedJobHandler.php index 316948e2..c8958cf9 100644 --- a/src/Services/QueuedJobHandler.php +++ b/src/Services/QueuedJobHandler.php @@ -4,6 +4,7 @@ use Monolog\Handler\AbstractProcessingHandler; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\ORM\DB; use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; /** @@ -56,6 +57,12 @@ protected function write(array $record) public function handleBatch(array $records) { + // Guard against handlers auto-flushing on destruct. + // When this is part of a PHPUnit run, the connection to the database can have already been closed. + if (!DB::is_active()) { + return; + } + foreach ($records as $record) { $this->job->addMessage($record['message'], $record['level_name'], $record['datetime']); };