Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed Sep 16, 2024
1 parent 48dcc9e commit 119a01f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 41 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require": {
"php": "^8.1",
"illuminate/contracts": "^10.0",
"lorisleiva/cron-translator": "^0.4.5",
"mtdowling/cron-expression": "^1.2",
"spatie/laravel-package-tools": "^1.14.0",
"symfony/dom-crawler": "^6.2",
Expand Down Expand Up @@ -77,4 +78,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
19 changes: 0 additions & 19 deletions database/factories/ModelFactory.php

This file was deleted.

19 changes: 0 additions & 19 deletions database/migrations/create_ok_table.php.stub

This file was deleted.

92 changes: 92 additions & 0 deletions src/Commands/StatusCommand.php
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));
}
}
4 changes: 2 additions & 2 deletions src/LaravelOKServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Vormkracht10\LaravelOK\Events\CheckFailed;
use Vormkracht10\LaravelOK\Jobs\QueueHeartbeatJob;
use Vormkracht10\LaravelOK\Listeners\SendCheckFailedNotification;
use Vormkracht10\LaravelOK\Commands\StatusCommand;

class LaravelOKServiceProvider extends PackageServiceProvider
{
Expand All @@ -19,17 +20,16 @@ public function configurePackage(Package $package): void
$package
->name('laravel-ok')
->hasConfigFile()
// ->hasMigration('create_laravel_ok_table')
->hasCommands(
DispatchQueueCheckJobsCommand::class,
RunChecksCommand::class,
SchedulerHeartbeatCommand::class,
StatusCommand::class,
)
->hasViews('ok')
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfigFile()
// ->publishMigrations()
->copyAndRegisterServiceProviderInApp()
->askToStarRepoOnGitHub('vormkracht10/laravel-ok');
});
Expand Down

0 comments on commit 119a01f

Please sign in to comment.