Skip to content
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

fix(apps): Remove jobs when an app gets disabled #50707

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshtrichards
Copy link
Member

  • Resolves: #

Summary

Automatically remove background jobs when an app gets disabled rather than waiting for the job to fail at the next run (where we currently disable it reactively).

Current behavior is reactive only and triggers an unnecessary warning that gets logged at the next attempt to run the job:

} catch (QueryException $e) {
if (class_exists($row['class'])) {
$class = $row['class'];
$job = new $class();
} else {
$this->logger->warning('failed to create instance of background job: ' . $row['class'], ['app' => 'cron', 'exception' => $e]);
// Remove job from disabled app or old version of an app
$this->removeById($row['id']);
return null;
}
}

(keeping that to catch apps that get disabled externally - or that fail to load in other ways; this PR just makes it so that apps that are disabled cleanly also have their background jobs removed).

TODO

  • ...

Checklist

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not add new methods to legacy classes, we are trying to get rid of them!

Most of OC_App is replaced by the AppManager.
In this case you can directly put the loop in the disableApp function I’d say, the code is quite short.
getJobList is also deprecated, should be \OCP\Server::get(IJobList::class), or DI of the joblist in the constructor. (I’d say Server::get is better here as it’s code that runs rarely)

@come-nc
Copy link
Contributor

come-nc commented Feb 6, 2025

Forgot to say that I do think the idea is good and should be implemented. It’s cleaner than waiting for jobs to fail indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants