Skip to content

Commit

Permalink
fix: delete background jobs by id when cleaning up
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed May 30, 2024
1 parent 0eb74d7 commit 1a9f7d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/private/BackgroundJob/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function remove($job, $argument = null): void {
}
}

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)));
Expand Down
8 changes: 8 additions & 0 deletions lib/public/BackgroundJob/IJobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public function scheduleAfter(string $job, int $runAfter, $argument = null): voi
*/
public function remove($job, $argument = null): void;

/**
* Remove a job from the list by id
*
* @param int $id
* @since 30.0.0
*/
public function removeById(int $id): void;

/**
* check if a job is in the list
*
Expand Down
6 changes: 5 additions & 1 deletion lib/public/BackgroundJob/QueuedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ final public function execute($jobList, ?ILogger $logger = null) {
* @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);
}
}

0 comments on commit 1a9f7d5

Please sign in to comment.