diff options
author | Benjamin Brahmer <info@b-brahmer.de> | 2023-03-20 14:08:52 +0100 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2023-08-22 09:47:11 +0200 |
commit | 17f0fc7f4a4ffeaa004227755c9926276904a9be (patch) | |
tree | 45dbc1691323a0849560a367f352be27cb29a193 /lib | |
parent | ca9e07b3ba6969a45f98c710c3a137299ad93b01 (diff) |
Add a command to check the job status and reset it
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Command/Updater/Job.php | 76 | ||||
-rw-r--r-- | lib/Service/UpdaterService.php | 20 |
2 files changed, 95 insertions, 1 deletions
diff --git a/lib/Command/Updater/Job.php b/lib/Command/Updater/Job.php new file mode 100644 index 000000000..4404a456e --- /dev/null +++ b/lib/Command/Updater/Job.php @@ -0,0 +1,76 @@ +<?php +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + */ + +namespace OCA\News\Command\Updater; + +use DateTime; +use OCP\Util; +use OCA\News\Service\StatusService; +use OCA\News\Service\UpdaterService; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class Job extends Command +{ + /** + * @var StatusService Status service + */ + private $statusService; + + /** + * @var UpdaterService Update service + */ + private $updaterService; + + public function __construct(StatusService $statusService, UpdaterService $updaterService) + { + parent::__construct(); + $this->statusService = $statusService; + $this->updaterService = $updaterService; + } + + /** + * @return void + */ + protected function configure() + { + $this->setName('news:updater:job') + ->addOption( + 'reset', + null, + InputOption::VALUE_NONE, + 'If the job should be reset, warning this might lead to issues.' + ) + ->setDescription('Console API for checking the update job status and to reset it.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $reset = (bool) $input->getOption('reset'); + + [$major, $minor, $micro] = Util::getVersion(); + + if ($major < 26) { + $output->writeln("Error: This only works with Nextcloud 26 or newer."); + return 1; + } + $output->writeln("Checking update Status"); + $date = new DateTime(); + $date->setTimestamp($this->statusService->getUpdateTime()); + $output->writeln("Last Execution was ".$date->format('Y-m-d H:i:s e')); + + if ($reset) { + $output->writeln("Attempting to reset the job."); + $this->updaterService->reset(); + $output->writeln("Done, job should execute on next schedule."); + } + return 0; + } +} diff --git a/lib/Service/UpdaterService.php b/lib/Service/UpdaterService.php index 5ab553d10..a67376de7 100644 --- a/lib/Service/UpdaterService.php +++ b/lib/Service/UpdaterService.php @@ -14,6 +14,9 @@ namespace OCA\News\Service; +use OCP\BackgroundJob\IJobList; +use OCA\News\Cron\UpdaterJob; + class UpdaterService { @@ -32,14 +35,19 @@ class UpdaterService */ private $itemService; + /** @var IJobList */ + private $jobList; + public function __construct( FolderServiceV2 $folderService, FeedServiceV2 $feedService, - ItemServiceV2 $itemService + ItemServiceV2 $itemService, + IJobList $jobList ) { $this->folderService = $folderService; $this->feedService = $feedService; $this->itemService = $itemService; + $this->jobList = $jobList; } @@ -60,4 +68,14 @@ class UpdaterService { $this->itemService->purgeOverThreshold(); } + + public function reset(): int + { + $myJobList = $this->jobList->getJobsIterator(UpdaterJob::class, 1, 0); + $job = $myJobList->current(); + + $this->jobList->resetBackgroundJob($job); + + return 0; + } } |