Skip to content
Open
Show file tree
Hide file tree
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 config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,19 @@
*/
'maintenance_window_start' => 1,

/**
* Background job classes that are never picked up by cron, webcron, AJAX
* or ``occ background-job:worker``. The jobs stay registered and can still
* be run manually with ``occ background-job:execute``.
*
* Use the fully qualified class names as listed by ``occ background-job:list``.
*
* Defaults to an empty array
*/
'excluded_jobs' => [
'OCA\\Files\\BackgroundJob\\DeleteOrphanedItems',
],

/**
* Log all LDAP requests into a file
*
Expand Down
6 changes: 6 additions & 0 deletions lib/private/BackgroundJob/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = nu
$query->andWhere($query->expr()->orX(...$orClasses));
}

$excludedClasses = $this->config->getSystemValue('excluded_jobs', []);
if (is_array($excludedClasses) && !empty($excludedClasses)) {
$excludedClasses = array_map(static fn ($class): string => ltrim((string)$class, '\\'), $excludedClasses);
$query->andWhere($query->expr()->notIn('class', $query->createNamedParameter($excludedClasses, IQueryBuilder::PARAM_STR_ARRAY)));
}

$result = $query->executeQuery();
$row = $result->fetchAssociative();
$result->closeCursor();
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/BackgroundJob/JobListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,43 @@ public function testGetNextSkipNonExisting(): void {
$this->assertEquals(2, $nextJob->getArgument());
}

public static function excludedJobClassProvider(): array {
return [
[TestJob::class],
['\\' . TestJob::class],
];
}

#[DataProvider(methodName: 'excludedJobClassProvider')]
public function testGetNextSkipsExcludedJobClasses(string $excludedClass): void {
$this->createTempJob(TestJob::class, 1, 0, 12345);
$this->createTempJob(TestParallelAwareJob::class, 2, 0, 12346);

$this->config->method('getSystemValue')
->with('excluded_jobs', [])
->willReturn([$excludedClass]);
$this->timeFactory->expects($this->atLeastOnce())
->method('getTime')
->willReturn(123456789);
$nextJob = $this->instance->getNext();

$this->assertInstanceOf(TestParallelAwareJob::class, $nextJob);
$this->assertEquals(2, $nextJob->getArgument());
}

public function testGetNextReturnsNullWhenOnlyExcludedJobsAreLeft(): void {
$this->createTempJob(TestJob::class, 1, 0, 12345);

$this->config->method('getSystemValue')
->with('excluded_jobs', [])
->willReturn([TestJob::class]);
$this->timeFactory->expects($this->atLeastOnce())
->method('getTime')
->willReturn(123456789);

$this->assertNull($this->instance->getNext());
}

/**
* @param $argument
*/
Expand Down
Loading