forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKernel.php
More file actions
64 lines (52 loc) · 1.67 KB
/
Kernel.php
File metadata and controls
64 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace App\Console;
use App\Jobs\ExecSpeedtest;
use App\Settings\GeneralSettings;
use Cron\CronExpression;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
$settings = new GeneralSettings();
/**
* Check for speedtests that need to run.
*/
$schedule->call(function () use ($settings) {
$ooklaServerId = null;
if (! blank($settings->speedtest_server)) {
$item = array_rand($settings->speedtest_server);
$ooklaServerId = $settings->speedtest_server[$item];
}
$speedtest = [
'ookla_server_id' => $ooklaServerId,
];
ExecSpeedtest::dispatch(
speedtest: $speedtest,
scheduled: true
);
})
->everyMinute()
->when(function () use ($settings) {
// Don't run if the schedule is missing (aka disabled)
if (blank($settings->speedtest_schedule)) {
return false;
}
// Evaluate if a run is needed based on the schedule
$cron = new CronExpression($settings->speedtest_schedule);
return $cron->isDue();
});
}
/**
* Register the commands for the application.
*/
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}