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: 4 additions & 0 deletions app/Enums/ResultStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@

enum ResultStatus: string implements HasColor, HasLabel
{
case Checking = 'checking';
case Completed = 'completed';
case Failed = 'failed';
case Running = 'running';
case Started = 'started';
case Skipped = 'skipped';

public function getColor(): ?string
{
return match ($this) {
self::Checking => 'info',
self::Completed => 'success',
self::Failed => 'danger',
self::Running => 'info',
self::Started => 'info',
self::Skipped => 'gray',
};
Expand Down
20 changes: 20 additions & 0 deletions app/Events/SpeedtestChecking.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Events;

use App\Models\Result;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class SpeedtestChecking
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Result $result,
) {}
}
20 changes: 20 additions & 0 deletions app/Events/SpeedtestRunning.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Events;

use App\Models\Result;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class SpeedtestRunning
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Result $result,
) {}
}
7 changes: 7 additions & 0 deletions app/Jobs/CheckForInternetConnectionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Actions\GetExternalIpAddress;
use App\Enums\ResultStatus;
use App\Events\SpeedtestChecking;
use App\Events\SpeedtestFailed;
use App\Models\Result;
use Illuminate\Bus\Batchable;
Expand All @@ -30,6 +31,12 @@ public function handle(): void
return;
}

$this->result->update([
'status' => ResultStatus::Checking,
]);

SpeedtestChecking::dispatch($this->result);

if (GetExternalIpAddress::run() !== false) {
return;
}
Expand Down
7 changes: 7 additions & 0 deletions app/Jobs/Ookla/RunSpeedtestJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enums\ResultStatus;
use App\Events\SpeedtestCompleted;
use App\Events\SpeedtestFailed;
use App\Events\SpeedtestRunning;
use App\Helpers\Ookla;
use App\Models\Result;
use Illuminate\Bus\Batchable;
Expand Down Expand Up @@ -41,6 +42,12 @@ public function handle(): void
return;
}

$this->result->update([
'status' => ResultStatus::Running,
]);

SpeedtestRunning::dispatch($this->result);

$command = array_filter([
'speedtest',
'--accept-license',
Expand Down