Skip to content

Commit df3352c

Browse files
committed
added config to enable speedtest schedule
1 parent c999009 commit df3352c

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

app/Jobs/ExecSpeedtest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ExecSpeedtest implements ShouldQueue
2323
* @return void
2424
*/
2525
public function __construct(
26-
public Speedtest|null $speedtest = null
26+
public array|null $speedtest = null
2727
) {}
2828

2929
/**
@@ -44,15 +44,9 @@ public function handle()
4444

4545
$output = $process->getOutput();
4646

47-
if (! blank($this->speedtest)) {
48-
$this->speedtest->results()->create([
49-
'data' => $output,
50-
]);
51-
} else {
52-
Result::create([
53-
'data' => $output,
54-
]);
55-
}
47+
Result::create([
48+
'data' => $output,
49+
]);
5650

5751
return 0;
5852
}

app/Jobs/SearchForSpeedtests.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace App\Jobs;
44

5-
use App\Models\Speedtest;
65
use Cron\CronExpression;
76
use Illuminate\Bus\Queueable;
87
use Illuminate\Contracts\Queue\ShouldBeUnique;
98
use Illuminate\Contracts\Queue\ShouldQueue;
109
use Illuminate\Foundation\Bus\Dispatchable;
1110
use Illuminate\Queue\InteractsWithQueue;
1211
use Illuminate\Queue\SerializesModels;
13-
use Illuminate\Support\Facades\Log;
12+
use Symfony\Component\Yaml\Yaml;
1413

1514
class SearchForSpeedtests implements ShouldQueue
1615
{
@@ -33,19 +32,16 @@ public function __construct()
3332
*/
3433
public function handle()
3534
{
36-
$tests = Speedtest::query()
37-
->where('next_run_at', now()->format('Y-m-d H:i'))
38-
->get();
35+
$config = Yaml::parseFile(
36+
base_path().'/config.yml'
37+
);
3938

40-
foreach ($tests as $item) {
41-
ExecSpeedtest::dispatch(speedtest: $item);
39+
$speedtest = $config['speedtest'];
4240

43-
$cron = new CronExpression($item->schedule);
41+
$cron = new CronExpression($speedtest['schedule']);
4442

45-
$item->next_run_at = $cron->getNextRunDate()->format('Y-m-d H:i');
46-
$item->save();
43+
if ($cron->isDue() && $speedtest['enabled']) {
44+
ExecSpeedtest::dispatch(speedtest: $speedtest);
4745
}
48-
49-
Log::info($tests);
5046
}
5147
}

config.example.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authentication: true # Set to false to disable authentication
33
influxdb:
44
enabled: true
5-
host_tag: 'speedtest'
5+
host_tag: 'speedtest-tracker'
66
retention: '30d'
77
notifications:
88
channels:
@@ -11,6 +11,7 @@ notifications:
1111
slack:
1212
webhook_url: null # Set as null to disable
1313
speedtest:
14+
enabled: true
1415
schedule: '*/60 * * * *' # every hour
1516
ookla_server_id: null # specify a server ID to use a sepecific server
16-
tz: 'America/New_York'
17+
tz: 'UTC'

0 commit comments

Comments
 (0)