-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command to check the job status and reset it
Signed-off-by: Benjamin Brahmer <[email protected]>
- Loading branch information
Showing
8 changed files
with
195 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bats | ||
|
||
# This only works with NC 26 | ||
|
||
load "helpers/settings" | ||
load "../test_helper/bats-support/load" | ||
load "../test_helper/bats-assert/load" | ||
|
||
TESTSUITE="Update" | ||
|
||
@test "[$TESTSUITE] Job status" { | ||
run ./occ news:updater:job | ||
|
||
assert_success | ||
} | ||
|
||
@test "[$TESTSUITE] Job reset" { | ||
run ./occ news:updater:job --reset | ||
|
||
assert_success | ||
} |
Submodule bats-assert
updated
3 files
+3 −2 | .github/workflows/tests.yml | |
+5 −8 | package.json | |
+1 −1 | test/test_helper.bash |