Skip to content

Commit 73f9b9f

Browse files
authored
[Feature] Check for internet connection before running a test (alexjustesen#1444)
1 parent b2c4c25 commit 73f9b9f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/Jobs/Speedtests/ExecuteOoklaSpeedtest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Queue\InteractsWithQueue;
1414
use Illuminate\Queue\SerializesModels;
1515
use Illuminate\Support\Arr;
16+
use Illuminate\Support\Facades\Http;
1617
use Symfony\Component\Process\Exception\ProcessFailedException;
1718
use Symfony\Component\Process\Process;
1819

@@ -41,6 +42,26 @@ public function __construct(
4142
*/
4243
public function handle(): void
4344
{
45+
/**
46+
* Check to make sure there is an internet connection first.
47+
*/
48+
try {
49+
Http::retry(3, 500)->get('https://google.com');
50+
} catch (\Throwable $th) {
51+
$this->result->update([
52+
'data' => [
53+
'type' => 'log',
54+
'level' => 'error',
55+
'message' => 'Could not resolve host.',
56+
],
57+
'status' => ResultStatus::Failed,
58+
]);
59+
60+
SpeedtestFailed::dispatch($this->result);
61+
62+
return;
63+
}
64+
4465
$options = array_filter([
4566
'speedtest',
4667
'--accept-license',

0 commit comments

Comments
 (0)