Skip to content

[backport 27]Multiple cron background jobs based on class - Patch - maybe need a new for nc28 #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: stable27
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
$endTime = time() + 14 * 60;

$executedJobs = [];
while ($job = $jobList->getNext($onlyTimeSensitive)) {
$jobClass = isset($argv[1]) ? $argv[1] : null;
while ($job = $jobList->getNext($onlyTimeSensitive, $jobClass)) {
if (isset($executedJobs[$job->getId()])) {
$jobList->unlockJob($job);
break;
Expand Down
10 changes: 7 additions & 3 deletions lib/private/BackgroundJob/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function getJobsIterator($job, ?int $limit, int $offset): iterable {
* Get the next job in the list
* @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.
*/
public function getNext(bool $onlyTimeSensitive = false): ?IJob {
public function getNext(bool $onlyTimeSensitive = false, string $jobClass = null): ?IJob {
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('jobs')
Expand All @@ -219,6 +219,10 @@ public function getNext(bool $onlyTimeSensitive = false): ?IJob {
$query->andWhere($query->expr()->eq('time_sensitive', $query->createNamedParameter(IJob::TIME_SENSITIVE, IQueryBuilder::PARAM_INT)));
}

if ($jobClass) {
$query->andWhere($query->expr()->eq('class', $query->createNamedParameter($jobClass)));
}

$result = $query->executeQuery();
$row = $result->fetch();
$result->closeCursor();
Expand Down Expand Up @@ -253,7 +257,7 @@ public function getNext(bool $onlyTimeSensitive = false): ?IJob {

if ($count === 0) {
// Background job already executed elsewhere, try again.
return $this->getNext($onlyTimeSensitive);
return $this->getNext($onlyTimeSensitive, $jobClass);
}

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

// Background job from disabled app, try again.
return $this->getNext($onlyTimeSensitive);
return $this->getNext($onlyTimeSensitive, $jobClass);
}

return $job;
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/BackgroundJob/DummyJobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getJobsIterator($job, ?int $limit, int $offset): array {
/**
* get the next job in the list
*/
public function getNext(bool $onlyTimeSensitive = false): ?IJob {
public function getNext(bool $onlyTimeSensitive = false, string $jobClass = null): ?IJob {
if (count($this->jobs) > 0) {
if ($this->last < (count($this->jobs) - 1)) {
$i = $this->last + 1;
Expand Down