Skip to content

Commit a92e2a2

Browse files
authored
[Feature] Made checking for internet connection optional (alexjustesen#1507)
1 parent c80fa8f commit a92e2a2

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

app/Jobs/Speedtests/ExecuteOoklaSpeedtest.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,7 @@ public function __construct(
4242
*/
4343
public function handle(): void
4444
{
45-
/**
46-
* Check for an internet connection first.
47-
*/
48-
$ping = new Ping(
49-
host: config('speedtest.ping_url'),
50-
timeout: 3,
51-
);
52-
53-
if ($ping->ping() === false) {
54-
$this->result->update([
55-
'data' => [
56-
'type' => 'log',
57-
'level' => 'error',
58-
'message' => 'Could not resolve host.',
59-
],
60-
'status' => ResultStatus::Failed,
61-
]);
62-
63-
SpeedtestFailed::dispatch($this->result);
64-
45+
if (! $this->checkForInternetConnection()) {
6546
return;
6647
}
6748

@@ -104,4 +85,34 @@ public function handle(): void
10485

10586
SpeedtestCompleted::dispatch($this->result);
10687
}
88+
89+
protected function checkForInternetConnection(): bool
90+
{
91+
// Skip checking for internet connection if ping url isn't set (disabled)
92+
if (blank(config('speedtest.ping_url'))) {
93+
return true;
94+
}
95+
96+
$ping = new Ping(
97+
host: config('speedtest.ping_url'),
98+
timeout: 3,
99+
);
100+
101+
if ($ping->ping() === false) {
102+
$this->result->update([
103+
'data' => [
104+
'type' => 'log',
105+
'level' => 'error',
106+
'message' => 'Could not resolve host.',
107+
],
108+
'status' => ResultStatus::Failed,
109+
]);
110+
111+
SpeedtestFailed::dispatch($this->result);
112+
113+
return false;
114+
}
115+
116+
return true;
117+
}
107118
}

config/speedtest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Speedtest settings.
3131
*/
32-
'ping_url' => env('SPEEDTEST_PING_URL', '1.1.1.1'),
32+
'ping_url' => env('SPEEDTEST_PING_URL'),
3333

3434
'schedule' => env('SPEEDTEST_SCHEDULE'),
3535

0 commit comments

Comments
 (0)