-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added commands to dispatch batch updates and individual updates (#19)
* Added start commands * cs fix * cs fixes
- Loading branch information
1 parent
d5eec1b
commit 0154bfe
Showing
7 changed files
with
151 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\UpdateSite; | ||
use App\Models\Site; | ||
use Illuminate\Console\Command; | ||
use App\Console\Traits\RequestTargetVersion; | ||
|
||
class PerformUpdate extends Command | ||
{ | ||
use RequestTargetVersion; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:perform-update {siteId}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Executes an update job for given site id'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
$targetVersion = $this->queryTargetVersion(); | ||
|
||
/** @var Site $site */ | ||
$site = Site::findOrFail($this->input->getArgument('siteId')); | ||
|
||
UpdateSite::dispatchSync( | ||
$site, | ||
$targetVersion | ||
); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Console\Traits\RequestTargetVersion; | ||
use App\Jobs\UpdateSite; | ||
use App\Models\Site; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class QueueUpdates extends Command | ||
{ | ||
use RequestTargetVersion; | ||
protected int $totalPushed = 0; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:queue-updates'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Queues updates for all applicable registered sites'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
$targetVersion = $this->queryTargetVersion(); | ||
|
||
$this->confirm("Are you sure you would like to push the updates for " . $targetVersion); | ||
|
||
$this->output->writeln('Pushing update jobs'); | ||
|
||
Site::query() | ||
->where( | ||
'cms_version', | ||
'like', | ||
$targetVersion[0] . '%' | ||
) | ||
->chunkById( | ||
100, | ||
function (Collection $chunk) use ($targetVersion) { | ||
// Show progress | ||
$this->output->write('.'); | ||
|
||
$this->totalPushed += $chunk->count(); | ||
|
||
// Push each site check to queue | ||
$chunk->each(fn ($site) => UpdateSite::dispatch($site, $targetVersion)); | ||
} | ||
); | ||
|
||
// Result | ||
$this->output->writeln(""); | ||
$this->output->writeln('Pushed ' . $this->totalPushed . ' pending jobs to queue'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace App\Console\Traits; | ||
|
||
use App\TUF\TufFetcher; | ||
|
||
trait RequestTargetVersion | ||
{ | ||
protected function queryTargetVersion(): string | ||
{ | ||
$releases = (new TufFetcher())->getReleases(); | ||
|
||
return $this->choice( // @phpstan-ignore-line | ||
"What's the target version?", | ||
$releases->map(fn ($release) => $release["version"])->values()->toArray() // @phpstan-ignore-line | ||
); | ||
} | ||
} |
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