generated from vormkracht10/laravel-package-template
-
-
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.
- Loading branch information
1 parent
48dcc9e
commit 119a01f
Showing
5 changed files
with
96 additions
and
41 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,92 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\LaravelOK\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Console\Scheduling\Schedule; | ||
use Lorisleiva\CronTranslator\CronTranslator; | ||
use Spatie\Emoji\Emoji; | ||
use Symfony\Component\Console\Helper\TableSeparator; | ||
use Vormkracht10\LaravelOK\Facades\OK; | ||
|
||
class StatusCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'ok:status {--F|filter=}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Show status for all registered checks'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$caches = OK::configuredChecks(); | ||
|
||
$frequencies = collect(app(Schedule::class)->events()) | ||
->mapWithKeys(function ($schedule) { | ||
return [$schedule->description => CronTranslator::translate($schedule->expression)]; | ||
}); | ||
|
||
$tableRows = []; | ||
|
||
foreach ($caches as $c) { | ||
$cache = $caches->current(); | ||
$parameters = $caches->getInfo(); | ||
|
||
if ( | ||
$this->option('filter') && | ||
! str_contains(strtolower($cache->getName()), strtolower($this->option('filter'))) | ||
) { | ||
continue; | ||
} | ||
|
||
$cached = $cache->getMeta($parameters); | ||
|
||
$row = [ | ||
$cache->isCached($parameters) ? Emoji::checkMarkButton() : Emoji::crossMark(), | ||
$cache->getName(), | ||
$cached ? readable_size(strlen(serialize($cached))) : 'N/A', | ||
$cached?->updated_at?->diffForHumans() ?: 'N/A', | ||
$frequencies[$cache->getName()] ?? 'N/A', | ||
]; | ||
|
||
if ($this->option('parameters')) { | ||
$row[] = $this->parseParameters($parameters); | ||
} | ||
|
||
$tableRows[] = $row; | ||
$tableRows[] = new TableSeparator(); | ||
} | ||
|
||
array_pop($tableRows); | ||
|
||
$this->table( | ||
[null, 'Cache', 'Size', 'Last Updated', 'Frequency'] + ($this->option('parameters') ? ['Parameters'] : []), | ||
$tableRows, | ||
'box', | ||
); | ||
} | ||
|
||
public function parseParameters($parameters) | ||
{ | ||
$queryString = http_build_query($parameters); | ||
|
||
return str_replace([ | ||
'=', | ||
'&', | ||
], [ | ||
': ', | ||
', ', | ||
], urldecode($queryString)); | ||
} | ||
} |
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