forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunSpeedtest.php
More file actions
51 lines (44 loc) · 1.54 KB
/
RunSpeedtest.php
File metadata and controls
51 lines (44 loc) · 1.54 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
<?php
namespace App\Actions\Fastcom;
use App\Enums\ResultService;
use App\Enums\ResultStatus;
use App\Events\SpeedtestWaiting;
use App\Jobs\CheckForInternetConnectionJob;
use App\Jobs\Fastcom\RunSpeedtestJob;
use App\Jobs\Ookla\BenchmarkSpeedtestJob;
use App\Jobs\Ookla\CompleteSpeedtestJob;
use App\Jobs\Ookla\SkipSpeedtestJob;
use App\Jobs\Ookla\StartSpeedtestJob;
use App\Models\Result;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Log;
use Lorisleiva\Actions\Concerns\AsAction;
use Throwable;
class RunSpeedtest
{
use AsAction;
public function handle(bool $scheduled = false, ?int $serverId = null, ?int $dispatchedBy = null): mixed
{
$result = Result::create([
'service' => ResultService::Fastcom,
'status' => ResultStatus::Waiting,
'scheduled' => $scheduled,
'dispatched_by' => $dispatchedBy,
]);
SpeedtestWaiting::dispatch($result);
Bus::batch([
[
new StartSpeedtestJob($result),
new CheckForInternetConnectionJob($result),
new SkipSpeedtestJob($result),
new RunSpeedtestJob($result),
new BenchmarkSpeedtestJob($result),
new CompleteSpeedtestJob($result),
],
])->catch(function (Batch $batch, ?Throwable $e) {
Log::error(sprintf('Speedtest batch "%s" failed for an unknown reason.', $batch->id));
})->name('Fast.com Speedtest')->dispatch();
return $result;
}
}