diff --git a/app/Actions/Ookla/SelectSpeedtestServer.php b/app/Actions/Ookla/SelectSpeedtestServer.php deleted file mode 100644 index 38c9b5754..000000000 --- a/app/Actions/Ookla/SelectSpeedtestServer.php +++ /dev/null @@ -1,33 +0,0 @@ -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, ); diff --git a/app/Jobs/Ookla/ProcessSpeedtestBatch.php b/app/Jobs/Ookla/ProcessSpeedtestBatch.php index d21ec52bf..59709bd06 100644 --- a/app/Jobs/Ookla/ProcessSpeedtestBatch.php +++ b/app/Jobs/Ookla/ProcessSpeedtestBatch.php @@ -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), diff --git a/app/Jobs/Ookla/SelectSpeedtestServerJob.php b/app/Jobs/Ookla/SelectSpeedtestServerJob.php new file mode 100644 index 000000000..f86e932f3 --- /dev/null +++ b/app/Jobs/Ookla/SelectSpeedtestServerJob.php @@ -0,0 +1,59 @@ +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; + } +} diff --git a/config/speedtest.php b/config/speedtest.php index 1c94e9e39..5370d7ac0 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -6,7 +6,7 @@ 'build_date' => Carbon::parse('2024-11-25'), - 'build_version' => 'v0.24.0', + 'build_version' => 'v0.24.1', /** * General settings.