mirror of
https://github.com/nextcloud/server.git
synced 2026-06-07 07:43:18 -04:00
Merge pull request #45920 from nextcloud/backport/45582/stable28
[stable28] delete background jobs by id when cleaning up
This commit is contained in:
commit
e57dd34846
4 changed files with 32 additions and 6 deletions
|
|
@ -135,7 +135,7 @@ class JobList implements IJobList {
|
|||
}
|
||||
}
|
||||
|
||||
protected function removeById(int $id): void {
|
||||
public function removeById(int $id): void {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->delete('jobs')
|
||||
->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
|
||||
|
|
|
|||
|
|
@ -79,6 +79,14 @@ interface IJobList {
|
|||
*/
|
||||
public function remove($job, $argument = null): void;
|
||||
|
||||
/**
|
||||
* Remove a job from the list by id
|
||||
*
|
||||
* @param int $id
|
||||
* @since 28.0.8
|
||||
*/
|
||||
public function removeById(int $id): void;
|
||||
|
||||
/**
|
||||
* check if a job is in the list
|
||||
*
|
||||
|
|
|
|||
|
|
@ -53,7 +53,11 @@ abstract class QueuedJob extends Job {
|
|||
* @since 25.0.0
|
||||
*/
|
||||
final public function start(IJobList $jobList): void {
|
||||
$jobList->remove($this, $this->argument);
|
||||
if ($this->id) {
|
||||
$jobList->removeById($this->id);
|
||||
} else {
|
||||
$jobList->remove($this, $this->argument);
|
||||
}
|
||||
parent::start($jobList);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
|
|||
private array $reserved = [];
|
||||
|
||||
private int $last = 0;
|
||||
private int $lastId = 0;
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
|
@ -41,6 +42,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
|
|||
$job = \OCP\Server::get($job);
|
||||
}
|
||||
$job->setArgument($argument);
|
||||
$job->setId($this->lastId);
|
||||
$this->lastId++;
|
||||
if (!$this->has($job, null)) {
|
||||
$this->jobs[] = $job;
|
||||
}
|
||||
|
|
@ -55,9 +58,20 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
|
|||
* @param mixed $argument
|
||||
*/
|
||||
public function remove($job, $argument = null): void {
|
||||
$index = array_search($job, $this->jobs);
|
||||
if ($index !== false) {
|
||||
unset($this->jobs[$index]);
|
||||
foreach ($this->jobs as $index => $listJob) {
|
||||
if (get_class($job) === get_class($listJob) && $job->getArgument() == $listJob->getArgument()) {
|
||||
unset($this->jobs[$index]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function removeById(int $id): void {
|
||||
foreach ($this->jobs as $index => $listJob) {
|
||||
if ($listJob->getId() === $id) {
|
||||
unset($this->jobs[$index]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +141,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
|
|||
}
|
||||
}
|
||||
|
||||
public function getById(int $id): IJob {
|
||||
public function getById(int $id): ?IJob {
|
||||
foreach ($this->jobs as $job) {
|
||||
if ($job->getId() === $id) {
|
||||
return $job;
|
||||
|
|
|
|||
Loading…
Reference in a new issue