Skip to content

Commit 423a8e5

Browse files
committed
Merge #256 [backport 27]Multiple cron background jobs based on class - Patch - maybe need a new for nc28
2 parents 4c7e817 + 6e4270a commit 423a8e5

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

cron.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@
142142
$endTime = time() + 14 * 60;
143143

144144
$executedJobs = [];
145-
while ($job = $jobList->getNext($onlyTimeSensitive)) {
145+
$jobClass = isset($argv[1]) ? $argv[1] : null;
146+
while ($job = $jobList->getNext($onlyTimeSensitive, $jobClass)) {
146147
if (isset($executedJobs[$job->getId()])) {
147148
$jobList->unlockJob($job);
148149
break;

lib/private/BackgroundJob/JobList.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function getJobsIterator($job, ?int $limit, int $offset): iterable {
206206
* Get the next job in the list
207207
* @return ?IJob the next job to run. Beware that this object may be a singleton and may be modified by the next call to buildJob.
208208
*/
209-
public function getNext(bool $onlyTimeSensitive = false): ?IJob {
209+
public function getNext(bool $onlyTimeSensitive = false, string $jobClass = null): ?IJob {
210210
$query = $this->connection->getQueryBuilder();
211211
$query->select('*')
212212
->from('jobs')
@@ -219,6 +219,10 @@ public function getNext(bool $onlyTimeSensitive = false): ?IJob {
219219
$query->andWhere($query->expr()->eq('time_sensitive', $query->createNamedParameter(IJob::TIME_SENSITIVE, IQueryBuilder::PARAM_INT)));
220220
}
221221

222+
if ($jobClass) {
223+
$query->andWhere($query->expr()->eq('class', $query->createNamedParameter($jobClass)));
224+
}
225+
222226
$result = $query->executeQuery();
223227
$row = $result->fetch();
224228
$result->closeCursor();
@@ -253,7 +257,7 @@ public function getNext(bool $onlyTimeSensitive = false): ?IJob {
253257

254258
if ($count === 0) {
255259
// Background job already executed elsewhere, try again.
256-
return $this->getNext($onlyTimeSensitive);
260+
return $this->getNext($onlyTimeSensitive, $jobClass);
257261
}
258262

259263
if ($job === null) {
@@ -266,7 +270,7 @@ public function getNext(bool $onlyTimeSensitive = false): ?IJob {
266270
$reset->executeStatement();
267271

268272
// Background job from disabled app, try again.
269-
return $this->getNext($onlyTimeSensitive);
273+
return $this->getNext($onlyTimeSensitive, $jobClass);
270274
}
271275

272276
return $job;

tests/lib/BackgroundJob/DummyJobList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function getJobsIterator($job, ?int $limit, int $offset): array {
9696
/**
9797
* get the next job in the list
9898
*/
99-
public function getNext(bool $onlyTimeSensitive = false): ?IJob {
99+
public function getNext(bool $onlyTimeSensitive = false, string $jobClass = null): ?IJob {
100100
if (count($this->jobs) > 0) {
101101
if ($this->last < (count($this->jobs) - 1)) {
102102
$i = $this->last + 1;

0 commit comments

Comments
 (0)