aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2024-04-08 17:25:51 +0200
committerJulien Veyssier <julien-nc@posteo.net>2024-05-02 16:43:41 +0200
commit1acc57b5c03b80ad5b6b5df7aff9df0fef83f14f (patch)
treeb8f0eaf7fca5bc99574a0f5a61ed24871aa90372 /core/Command
parenta5f244a58b6cfcc4feb8d8bdf33b40f983c342cb (diff)
downloadnextcloud-server-1acc57b5c03b80ad5b6b5df7aff9df0fef83f14f.tar.gz
nextcloud-server-1acc57b5c03b80ad5b6b5df7aff9df0fef83f14f.zip
feat(bg-jobs): allow setting a job class list instead of a single class in cron.php and the job worker occ command
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'core/Command')
-rw-r--r--core/Command/Background/JobBase.php6
-rw-r--r--core/Command/Background/JobWorker.php36
2 files changed, 32 insertions, 10 deletions
diff --git a/core/Command/Background/JobBase.php b/core/Command/Background/JobBase.php
index 4385783a7ee..94c9e1611ea 100644
--- a/core/Command/Background/JobBase.php
+++ b/core/Command/Background/JobBase.php
@@ -35,8 +35,10 @@ abstract class JobBase extends \OC\Core\Command\Base {
protected IJobList $jobList;
protected LoggerInterface $logger;
- public function __construct(IJobList $jobList,
- LoggerInterface $logger) {
+ public function __construct(
+ IJobList $jobList,
+ LoggerInterface $logger
+ ) {
parent::__construct();
$this->jobList = $jobList;
$this->logger = $logger;
diff --git a/core/Command/Background/JobWorker.php b/core/Command/Background/JobWorker.php
index d6aab0e83bc..8b7bb6b6fba 100644
--- a/core/Command/Background/JobWorker.php
+++ b/core/Command/Background/JobWorker.php
@@ -40,9 +40,9 @@ class JobWorker extends JobBase {
->setName('background-job:worker')
->setDescription('Run a background job worker')
->addArgument(
- 'job-class',
+ 'job-classes',
InputArgument::OPTIONAL,
- 'The class of the job in the database'
+ 'The classes of the jobs to look for in the database, comma-separated'
)
->addOption(
'once',
@@ -61,11 +61,31 @@ class JobWorker extends JobBase {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $jobClass = $input->getArgument('job-class');
+ $jobClassesString = $input->getArgument('job-classes');
+ // only keep non-empty strings
+ $jobClasses = $jobClassesString === null
+ ? null
+ : array_filter(
+ explode(',', $jobClassesString),
+ static function (string $jobClass) {
+ return strlen($jobClass) > 0;
+ }
+ );
+
+ if ($jobClasses !== null) {
+ // no class
+ if (count($jobClasses) === 0) {
+ $output->writeln('<error>Invalid job class list supplied</error>');
+ return 1;
+ }
- if ($jobClass && !class_exists($jobClass)) {
- $output->writeln('<error>Invalid job class</error>');
- return 1;
+ // at least one invalid class
+ foreach ($jobClasses as $jobClass) {
+ if (!class_exists($jobClass)) {
+ $output->writeln('<error>Invalid job class: ' . $jobClass . '</error>');
+ return 1;
+ }
+ }
}
while (true) {
@@ -80,10 +100,10 @@ class JobWorker extends JobBase {
$this->printSummary($input, $output);
usleep(50000);
- $job = $this->jobList->getNext(false, $jobClass);
+ $job = $this->jobList->getNext(false, $jobClasses);
if (!$job) {
if ($input->getOption('once') === true) {
- $output->writeln('No job of class ' . $jobClass . ' is currently queued', OutputInterface::VERBOSITY_VERBOSE);
+ $output->writeln('No job of classes ' . $jobClassesString . ' is currently queued', OutputInterface::VERBOSITY_VERBOSE);
$output->writeln('Exiting...', OutputInterface::VERBOSITY_VERBOSE);
break;
}