Run::handle()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 1
nop 0
1
<?php
2
3
namespace Infinitypaul\LaravelUptime\Commands;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Console\Command;
7
use Infinitypaul\LaravelUptime\Commands\Traits\CanForce;
8
use Infinitypaul\LaravelUptime\Endpoint;
9
use Infinitypaul\LaravelUptime\Scheduler\Kernel;
10
use Infinitypaul\LaravelUptime\Tasks\PingEndPoint;
11
12
class Run extends Command
13
{
14
    use CanForce;
15
16
    protected $client;
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'uptime:run {--F|force}';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Run The Whole Endpoint';
30
31
    /**
32
     * Create a new command instance.
33
     *
34
     * @param \GuzzleHttp\Client $client
35
     */
36
    public function __construct(Client $client)
37
    {
38
        parent::__construct();
39
        $this->client = $client;
40
    }
41
42
    /**
43
     * Execute the console command.
44
     *
45
     * @return mixed
46
     */
47
    public function handle()
48
    {
49
        $kernel = new Kernel();
50
        //$endpoints = Endpoint::get();
51
52
        Endpoint::orderBy('id')->chunk(100, function ($endpoints) use ($kernel) {
53
            foreach ($endpoints as $endpoint) {
54
                $kernel->add(
55
                    new PingEndPoint($endpoint, $this->client)
56
                )->everyMinutes(
57
                    $this->isForced() ? 1 : $endpoint->frequency
58
                );
59
            }
60
            $kernel->run();
61
        });
62
    }
63
}
64