From bf78bbde255776a9e3b5a29597c7bdb465b8c65e Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Tue, 13 Sep 2022 15:42:55 -0400 Subject: [PATCH] Use defined speedtest server (#7) --- app/Console/Commands/RunSpeedtest.php | 8 +++++++- app/Jobs/ExecSpeedtest.php | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/RunSpeedtest.php b/app/Console/Commands/RunSpeedtest.php index 5880d0606..c8a4aa612 100644 --- a/app/Console/Commands/RunSpeedtest.php +++ b/app/Console/Commands/RunSpeedtest.php @@ -29,7 +29,13 @@ class RunSpeedtest extends Command */ public function handle() { - ExecSpeedtest::dispatch(); + $speedtest = []; + + if ($this->argument('server')) { + $speedtest = array_merge($speedtest, ['ookla_server_id' => $this->argument('server')]); + } + + ExecSpeedtest::dispatch(speedtest: $speedtest); $this->info('✅ added manual speedtest to the queue'); diff --git a/app/Jobs/ExecSpeedtest.php b/app/Jobs/ExecSpeedtest.php index 059320a67..90f42966a 100644 --- a/app/Jobs/ExecSpeedtest.php +++ b/app/Jobs/ExecSpeedtest.php @@ -33,7 +33,19 @@ public function __construct( */ public function handle() { - $process = new Process(['speedtest', '--accept-license', '--format=json']); + $args = [ + 'speedtest', + '--accept-license', + '--format=json', + ]; + + if (! blank($this->speedtest)) { + if (! blank($this->speedtest['ookla_server_id'])) { + $args = array_merge($args, ['--server-id='.$this->speedtest['ookla_server_id']]); + } + } + + $process = new Process($args); $process->run(); if (! $process->isSuccessful()) {