Skip to content

Commit 4f3b644

Browse files
authored
[Feature] Added result checking and running statuses (alexjustesen#1812)
added result checking and running statuses
1 parent 1db48bf commit 4f3b644

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

app/Enums/ResultStatus.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
enum ResultStatus: string implements HasColor, HasLabel
1010
{
11+
case Checking = 'checking';
1112
case Completed = 'completed';
1213
case Failed = 'failed';
14+
case Running = 'running';
1315
case Started = 'started';
1416
case Skipped = 'skipped';
1517

1618
public function getColor(): ?string
1719
{
1820
return match ($this) {
21+
self::Checking => 'info',
1922
self::Completed => 'success',
2023
self::Failed => 'danger',
24+
self::Running => 'info',
2125
self::Started => 'info',
2226
self::Skipped => 'gray',
2327
};

app/Events/SpeedtestChecking.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Models\Result;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Foundation\Events\Dispatchable;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class SpeedtestChecking
11+
{
12+
use Dispatchable, InteractsWithSockets, SerializesModels;
13+
14+
/**
15+
* Create a new event instance.
16+
*/
17+
public function __construct(
18+
public Result $result,
19+
) {}
20+
}

app/Events/SpeedtestRunning.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Models\Result;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Foundation\Events\Dispatchable;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class SpeedtestRunning
11+
{
12+
use Dispatchable, InteractsWithSockets, SerializesModels;
13+
14+
/**
15+
* Create a new event instance.
16+
*/
17+
public function __construct(
18+
public Result $result,
19+
) {}
20+
}

app/Jobs/CheckForInternetConnectionJob.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Actions\GetExternalIpAddress;
66
use App\Enums\ResultStatus;
7+
use App\Events\SpeedtestChecking;
78
use App\Events\SpeedtestFailed;
89
use App\Models\Result;
910
use Illuminate\Bus\Batchable;
@@ -30,6 +31,12 @@ public function handle(): void
3031
return;
3132
}
3233

34+
$this->result->update([
35+
'status' => ResultStatus::Checking,
36+
]);
37+
38+
SpeedtestChecking::dispatch($this->result);
39+
3340
if (GetExternalIpAddress::run() !== false) {
3441
return;
3542
}

app/Jobs/Ookla/RunSpeedtestJob.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Enums\ResultStatus;
66
use App\Events\SpeedtestCompleted;
77
use App\Events\SpeedtestFailed;
8+
use App\Events\SpeedtestRunning;
89
use App\Helpers\Ookla;
910
use App\Models\Result;
1011
use Illuminate\Bus\Batchable;
@@ -41,6 +42,12 @@ public function handle(): void
4142
return;
4243
}
4344

45+
$this->result->update([
46+
'status' => ResultStatus::Running,
47+
]);
48+
49+
SpeedtestRunning::dispatch($this->result);
50+
4451
$command = array_filter([
4552
'speedtest',
4653
'--accept-license',

0 commit comments

Comments
 (0)