Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Actions/CheckForScheduledSpeedtests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,7 +18,7 @@ public function handle(): void
return;
}

StartSpeedtest::runIf(
RunSpeedtest::runIf(
$this->isSpeedtestDue(schedule: $schedule),
scheduled: true,
);
Expand Down
53 changes: 53 additions & 0 deletions app/Actions/Ookla/RunSpeedtest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Actions\Ookla;

use App\Enums\ResultService;
use App\Enums\ResultStatus;
use App\Events\SpeedtestWaiting;
use App\Jobs\CheckForInternetConnectionJob;
use App\Jobs\Ookla\BenchmarkSpeedtestJob;
use App\Jobs\Ookla\CompleteSpeedtestJob;
use App\Jobs\Ookla\RunSpeedtestJob;
use App\Jobs\Ookla\SelectSpeedtestServerJob;
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): mixed
{
$result = Result::create([
'data->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;
}
}
33 changes: 0 additions & 33 deletions app/Actions/Ookla/StartSpeedtest.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/V1/RunSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +51,7 @@ public function __invoke(Request $request)
);
}

$result = StartSpeedtest::run(
$result = RunSpeedtestAction::run(
serverId: $validated['server_id'] ?? null,
);

Expand Down
44 changes: 0 additions & 44 deletions app/Jobs/Ookla/ProcessSpeedtestBatch.php

This file was deleted.

5 changes: 2 additions & 3 deletions app/Livewire/Topbar/RunSpeedtestAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);

Expand Down