Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/private/BackgroundJob/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use function strlen;

class JobList implements IJobList {
/** @var array<string, int> */
protected array $alreadyVisitedParallelBlocked = [];

public function __construct(
protected IDBConnection $connection,
protected IConfig $config,
Expand Down Expand Up @@ -198,6 +201,12 @@ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = nu
$job = $this->buildJob($row);

if ($job instanceof IParallelAwareJob && !$job->getAllowParallelRuns() && $this->hasReservedJob(get_class($job))) {
if (!isset($this->alreadyVisitedParallelBlocked[get_class($job)])) {
$this->alreadyVisitedParallelBlocked[get_class($job)] = $job->getId();
} elseif ($this->alreadyVisitedParallelBlocked[get_class($job)] === $job->getId()) {
$this->logger->info('Skipped through all jobs and revisited a IParallelAwareJob blocked job again, giving up.', ['app' => 'cron']);
return null;
}
$this->logger->info('Skipping ' . get_class($job) . ' job with ID ' . $job->getId() . ' because another job with the same class is already running', ['app' => 'cron']);

$update = $this->connection->getQueryBuilder();
Expand All @@ -210,6 +219,10 @@ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = nu
return $this->getNext($onlyTimeSensitive, $jobClasses);
}

if ($job !== null && isset($this->alreadyVisitedParallelBlocked[get_class($job)])) {
unset($this->alreadyVisitedParallelBlocked[get_class($job)]);
}

if ($job instanceof \OCP\BackgroundJob\TimedJob) {
$now = $this->timeFactory->getTime();
$nextPossibleRun = $job->getLastRun() + $job->getInterval();
Expand Down
Loading