diff --git a/app/Actions/CheckForScheduledSpeedtests.php b/app/Actions/CheckForScheduledSpeedtests.php index 5f1890790..47098bf34 100644 --- a/app/Actions/CheckForScheduledSpeedtests.php +++ b/app/Actions/CheckForScheduledSpeedtests.php @@ -2,7 +2,7 @@ namespace App\Actions; -use App\Actions\Ookla\StartSpeedtest; +use App\Actions\Ookla\RunSpeedtest; use Cron\CronExpression; use Lorisleiva\Actions\Concerns\AsAction; @@ -18,7 +18,7 @@ public function handle(): void return; } - StartSpeedtest::runIf( + RunSpeedtest::runIf( $this->isSpeedtestDue(schedule: $schedule), scheduled: true, ); diff --git a/app/Actions/Ookla/RunSpeedtest.php b/app/Actions/Ookla/RunSpeedtest.php new file mode 100644 index 000000000..0d6a87a87 --- /dev/null +++ b/app/Actions/Ookla/RunSpeedtest.php @@ -0,0 +1,53 @@ +server->id' => $serverId, + 'service' => ResultService::Ookla, + 'status' => ResultStatus::Waiting, + 'scheduled' => $scheduled, + ]); + + SpeedtestWaiting::dispatch($result); + + Bus::batch([ + [ + new StartSpeedtestJob($result), + new CheckForInternetConnectionJob($result), + new SkipSpeedtestJob($result), + new SelectSpeedtestServerJob($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('Ookla Speedtest')->dispatch(); + + return $result; + } +} diff --git a/app/Actions/Ookla/StartSpeedtest.php b/app/Actions/Ookla/StartSpeedtest.php deleted file mode 100644 index cbcda90dd..000000000 --- a/app/Actions/Ookla/StartSpeedtest.php +++ /dev/null @@ -1,33 +0,0 @@ -server->id' => $serverId, - 'service' => ResultService::Ookla, - 'status' => ResultStatus::Waiting, - 'scheduled' => $scheduled, - ]); - - ProcessSpeedtestBatch::dispatch( - result: $result, - ); - - SpeedtestWaiting::dispatch($result); - - return $result; - } -} diff --git a/app/Http/Controllers/Api/V1/RunSpeedtest.php b/app/Http/Controllers/Api/V1/RunSpeedtest.php index a68f6baa7..e5b97b736 100644 --- a/app/Http/Controllers/Api/V1/RunSpeedtest.php +++ b/app/Http/Controllers/Api/V1/RunSpeedtest.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Api\V1; -use App\Actions\Ookla\StartSpeedtest; +use App\Actions\Ookla\RunSpeedtest as RunSpeedtestAction; use App\Http\Resources\V1\ResultResource; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -51,7 +51,7 @@ public function __invoke(Request $request) ); } - $result = StartSpeedtest::run( + $result = RunSpeedtestAction::run( serverId: $validated['server_id'] ?? null, ); diff --git a/app/Jobs/Ookla/ProcessSpeedtestBatch.php b/app/Jobs/Ookla/ProcessSpeedtestBatch.php deleted file mode 100644 index 71575fdc7..000000000 --- a/app/Jobs/Ookla/ProcessSpeedtestBatch.php +++ /dev/null @@ -1,44 +0,0 @@ -result), - new CheckForInternetConnectionJob($this->result), - new SkipSpeedtestJob($this->result), - new SelectSpeedtestServerJob($this->result), - new RunSpeedtestJob($this->result), - new BenchmarkSpeedtestJob($this->result), - new CompleteSpeedtestJob($this->result), - ], - ])->catch(function (Batch $batch, ?Throwable $e) { - Log::error(sprintf('Speedtest batch "%s" failed for an unknown reason.', $batch->id)); - })->name('Ookla Speedtest')->dispatch(); - } -} diff --git a/app/Livewire/Topbar/RunSpeedtestAction.php b/app/Livewire/Topbar/RunSpeedtestAction.php index 03b6a910d..648c136d1 100644 --- a/app/Livewire/Topbar/RunSpeedtestAction.php +++ b/app/Livewire/Topbar/RunSpeedtestAction.php @@ -3,7 +3,7 @@ namespace App\Livewire\Topbar; use App\Actions\GetOoklaSpeedtestServers; -use App\Actions\Ookla\StartSpeedtest; +use App\Actions\Ookla\RunSpeedtest; use App\Helpers\Ookla; use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; @@ -51,8 +51,7 @@ public function speedtestAction(): Action ->action(function (array $data) { $serverId = $data['server_id'] ?? null; - StartSpeedtest::run( - scheduled: false, + RunSpeedtest::run( serverId: $serverId, );