diff options
-rw-r--r-- | core/Command/Background/JobWorker.php | 28 | ||||
-rw-r--r-- | cron.php | 18 |
2 files changed, 13 insertions, 33 deletions
diff --git a/core/Command/Background/JobWorker.php b/core/Command/Background/JobWorker.php index 0cfe9db940b..0f160e44278 100644 --- a/core/Command/Background/JobWorker.php +++ b/core/Command/Background/JobWorker.php @@ -53,8 +53,8 @@ class JobWorker extends JobBase { ->setDescription('Run a background job worker') ->addArgument( 'job-classes', - InputArgument::OPTIONAL, - 'The classes of the jobs to look for in the database, comma-separated' + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'The classes of the jobs to look for in the database' ) ->addOption( 'once', @@ -73,25 +73,11 @@ class JobWorker extends JobBase { } protected function execute(InputInterface $input, OutputInterface $output): int { - $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; - } - ); + $jobClasses = $input->getArgument('job-classes'); + $jobClasses = empty($jobClasses) ? null : $jobClasses; if ($jobClasses !== null) { - // no class - if (count($jobClasses) === 0) { - $output->writeln('<error>Invalid job class list supplied</error>'); - return 1; - } - - // at least one invalid class + // at least one class is invalid foreach ($jobClasses as $jobClass) { if (!class_exists($jobClass)) { $output->writeln('<error>Invalid job class: ' . $jobClass . '</error>'); @@ -115,10 +101,10 @@ class JobWorker extends JobBase { $job = $this->jobList->getNext(false, $jobClasses); if (!$job) { if ($input->getOption('once') === true) { - if ($jobClassesString === null) { + if ($jobClasses === null) { $output->writeln('No job is currently queued', OutputInterface::VERBOSITY_VERBOSE); } else { - $output->writeln('No job of classes ' . $jobClassesString . ' is currently queued', OutputInterface::VERBOSITY_VERBOSE); + $output->writeln('No job of classes [' . implode(', ', $jobClasses) . '] is currently queued', OutputInterface::VERBOSITY_VERBOSE); } $output->writeln('Exiting...', OutputInterface::VERBOSITY_VERBOSE); break; @@ -62,10 +62,10 @@ try { Run the background job routine Usage: - php -f cron.php -- [-h] [<job-classes>] + php -f cron.php -- [-h] [<job-classes>...] Arguments: - job-classes Optional job class comma-separated list to only run those jobs + job-classes Optional job class list to only run those jobs Options: -h, --help Display this help message' . PHP_EOL; @@ -175,16 +175,10 @@ Options: $endTime = time() + 14 * 60; $executedJobs = []; - // a specific job class list can optionally be given as first argument - // only keep non-empty strings - $jobClasses = isset($argv[1]) - ? array_filter( - explode(',', $argv[1]), - static function (string $jobClass) { - return strlen($jobClass) > 0; - } - ) - : null; + // a specific job class list can optionally be given as argument + $jobClasses = array_slice($argv, 1); + $jobClasses = empty($jobClasses) ? null : $jobClasses; + while ($job = $jobList->getNext($onlyTimeSensitive, $jobClasses)) { if (isset($executedJobs[$job->getId()])) { $jobList->unlockJob($job); |