1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ProtoneMedia\ApiHealth\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use ProtoneMedia\ApiHealth\Checkers\Executor; |
7
|
|
|
use ProtoneMedia\ApiHealth\Runner; |
8
|
|
|
|
9
|
|
|
class RunCheckers extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'api-health:run-checkers {--force}'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Run the configured checkers'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Gets the passing and failing checkers from the Runner |
27
|
|
|
* and presents them in a table. |
28
|
|
|
* |
29
|
|
|
* @return null |
30
|
|
|
*/ |
31
|
|
|
public function handle() |
32
|
|
|
{ |
33
|
|
|
$runner = Runner::fromConfig(); |
34
|
|
|
|
35
|
|
|
if ($this->option('force')) { |
36
|
|
|
$runner->ignoreScheduling(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$failed = $runner->failed(); |
40
|
|
|
|
41
|
|
|
$passes = $runner->passes(); |
42
|
|
|
|
43
|
|
|
$this->info('Total checkers run: ' . ($failed->count() + $passes->count())); |
44
|
|
|
|
45
|
|
|
if ($passes->isNotEmpty()) { |
46
|
|
|
$this->line(''); |
47
|
|
|
$this->info('Passing checkers:'); |
48
|
|
|
$this->table(['Checker'], $passes->map(function (Executor $executor) { |
49
|
|
|
return [get_class($executor->getChecker())]; |
50
|
|
|
})); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($failed->isNotEmpty()) { |
54
|
|
|
$this->line(''); |
55
|
|
|
$this->error('Failed checkers:'); |
56
|
|
|
$this->table(['Checker', 'Exception'], $failed->map(function (Executor $executor) { |
57
|
|
|
return [ |
58
|
|
|
get_class($executor->getChecker()), |
59
|
|
|
$executor->getException()->getMessage(), |
60
|
|
|
]; |
61
|
|
|
})); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|