-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/selection-pop-up
- Loading branch information
Showing
32 changed files
with
778 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Actions; | ||
|
||
use App\Actions\Ookla\StartSpeedtest; | ||
use Cron\CronExpression; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class CheckForScheduledSpeedtests | ||
{ | ||
use AsAction; | ||
|
||
public function handle(): void | ||
{ | ||
$schedule = config('speedtest.schedule'); | ||
|
||
if (blank($schedule) || $schedule === false) { | ||
return; | ||
} | ||
|
||
StartSpeedtest::runIf( | ||
$this->isSpeedtestDue(schedule: $schedule), | ||
scheduled: true, | ||
); | ||
} | ||
|
||
/** | ||
* Assess if a speedtest is due to run based on the schedule. | ||
*/ | ||
private function isSpeedtestDue(string $schedule): bool | ||
{ | ||
$cron = new CronExpression($schedule); | ||
|
||
return $cron->isDue( | ||
currentTime: now(), | ||
timeZone: config('app.display_timezone') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Actions; | ||
|
||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Http; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Str; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class GetExternalIpAddress | ||
{ | ||
use AsAction; | ||
|
||
public function handle(): bool|string | ||
{ | ||
$externalIp = Cache::remember('external_ip', 30, function (): bool|string { | ||
$response = Http::retry(3, 100) | ||
->get('https://icanhazip.com/'); | ||
|
||
if ($response->failed()) { | ||
$message = sprintf('Failed to fetch external IP address, %d', $response->status()); | ||
|
||
Log::warning($message); | ||
|
||
return false; | ||
} | ||
|
||
return Str::trim($response->body()); | ||
}); | ||
|
||
return $externalIp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Actions\Ookla; | ||
|
||
use Illuminate\Support\Arr; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class SelectSpeedtestServer | ||
{ | ||
use AsAction; | ||
|
||
public function handle(): string | ||
{ | ||
$servers = config('speedtest.servers'); | ||
|
||
if (blank($servers)) { | ||
return ''; | ||
} | ||
|
||
$servers = array_filter( | ||
array_map( | ||
'trim', | ||
explode(',', $servers), | ||
), | ||
); | ||
|
||
if (count($servers) < 1) { | ||
return ''; | ||
} | ||
|
||
return Arr::random($servers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Actions\Ookla; | ||
|
||
use App\Enums\ResultService; | ||
use App\Enums\ResultStatus; | ||
use App\Events\SpeedtestStarted; | ||
use App\Jobs\Ookla\ProcessSpeedtestBatch; | ||
use App\Models\Result; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class StartSpeedtest | ||
{ | ||
use AsAction; | ||
|
||
public function handle(bool $scheduled = false): void | ||
{ | ||
$result = Result::create([ | ||
'service' => ResultService::Ookla, | ||
'status' => ResultStatus::Started, | ||
'scheduled' => $scheduled, | ||
]); | ||
|
||
$serverId = SelectSpeedtestServer::run(); | ||
|
||
if (! blank($serverId)) { | ||
$result->update([ | ||
'data->server->id' => $serverId, | ||
]); | ||
} | ||
|
||
ProcessSpeedtestBatch::dispatch( | ||
result: $result, | ||
); | ||
|
||
SpeedtestStarted::dispatch($result); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.