Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-avg-to-charts
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvg93 authored Nov 25, 2024
2 parents 46bd341 + 91b699e commit 58a9655
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 44 deletions.
33 changes: 0 additions & 33 deletions app/Actions/Ookla/SelectSpeedtestServer.php

This file was deleted.

11 changes: 1 addition & 10 deletions app/Actions/Ookla/StartSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ class StartSpeedtest
public function handle(bool $scheduled = false, ?int $serverId = null): void
{
$result = Result::create([
'data->server->id' => $serverId,
'service' => ResultService::Ookla,
'status' => ResultStatus::Started,
'scheduled' => $scheduled,
]);

if (blank($serverId)) {
$serverId = SelectSpeedtestServer::run();
}

if (! blank($serverId)) {
$result->update([
'data->server->id' => $serverId,
]);
}

ProcessSpeedtestBatch::dispatch(
result: $result,
);
Expand Down
1 change: 1 addition & 0 deletions app/Jobs/Ookla/ProcessSpeedtestBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function handle(): void
[
new CheckForInternetConnectionJob($this->result),
new SkipSpeedtestJob($this->result),
new SelectSpeedtestServerJob($this->result),
new RunSpeedtestJob($this->result),
new BenchmarkSpeedtestJob($this->result),
new CompleteSpeedtestJob($this->result),
Expand Down
59 changes: 59 additions & 0 deletions app/Jobs/Ookla/SelectSpeedtestServerJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Jobs\Ookla;

use App\Models\Result;
use Illuminate\Bus\Batchable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Arr;

class SelectSpeedtestServerJob implements ShouldQueue
{
use Batchable, Queueable;

/**
* Create a new job instance.
*/
public function __construct(
public Result $result,
) {}

/**
* Execute the job.
*/
public function handle(): void
{
if ($this->batch()->cancelled()) {
return;
}

$serverId = $this->result->server_id
?? $this->getConfigServer();

if ($this->result->server_id != $serverId) {
$this->result->update([
'data->server->id' => $serverId,
]);
}
}

/**
* Get a server from the config servers list.
*/
private function getConfigServer(): ?string
{
$servers = config('speedtest.servers');

$servers = array_filter(
array_map(
'trim',
explode(',', $servers),
),
);

return count($servers) > 0
? Arr::random($servers)
: null;
}
}
2 changes: 1 addition & 1 deletion config/speedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'build_date' => Carbon::parse('2024-11-25'),

'build_version' => 'v0.24.0',
'build_version' => 'v0.24.1',

/**
* General settings.
Expand Down

0 comments on commit 58a9655

Please sign in to comment.