forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunOoklaSpeedtest.php
More file actions
78 lines (64 loc) · 1.96 KB
/
RunOoklaSpeedtest.php
File metadata and controls
78 lines (64 loc) · 1.96 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace App\Console\Commands;
use App\Jobs\ExecSpeedtest;
use App\Settings\GeneralSettings;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
class RunOoklaSpeedtest extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:run-ookla-speedtest
{--scheduled : Option used to determine if the command was run from the scheduler}
{server? : Specify an Ookla server to run the test against}';
/**
* The console command description.
*
* @var string
*/
protected $description = "Run a speedtest against Ookla's service.";
/**
* Execute the console command.
*/
public function handle()
{
$config = [];
$settings = new GeneralSettings();
if (is_array($settings->speedtest_server) && count($settings->speedtest_server)) {
$config = array_merge($config, [
'ookla_server_id' => Arr::random($settings->speedtest_server),
]);
}
if (! $this->option('scheduled')) {
if ($this->argument('server')) {
$config = array_merge($config, [
'ookla_server_id' => $this->argument('server'),
]);
}
try {
ExecSpeedtest::dispatch(
speedtest: $config,
scheduled: false
);
} catch (\Throwable $th) {
Log::warning($th);
return Command::FAILURE;
}
return Command::SUCCESS;
}
try {
ExecSpeedtest::dispatch(
speedtest: $config,
scheduled: true
);
} catch (\Throwable $th) {
Log::warning($th);
return Command::FAILURE;
}
return Command::SUCCESS;
}
}