|
2 | 2 |
|
3 | 3 | namespace App\Jobs; |
4 | 4 |
|
| 5 | +use App\Settings\GeneralSettings; |
5 | 6 | use Cron\CronExpression; |
6 | 7 | use Illuminate\Bus\Queueable; |
7 | 8 | use Illuminate\Contracts\Queue\ShouldQueue; |
8 | 9 | use Illuminate\Foundation\Bus\Dispatchable; |
9 | 10 | use Illuminate\Queue\InteractsWithQueue; |
10 | 11 | use Illuminate\Queue\SerializesModels; |
11 | | -use Illuminate\Support\Facades\File; |
12 | | -use Symfony\Component\Yaml\Yaml; |
13 | 12 |
|
14 | 13 | class SearchForSpeedtests implements ShouldQueue |
15 | 14 | { |
16 | 15 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
17 | 16 |
|
18 | | - /** |
19 | | - * Create a new job instance. |
20 | | - * |
21 | | - * @return void |
22 | | - */ |
23 | | - public function __construct() |
24 | | - { |
25 | | - // |
26 | | - } |
27 | | - |
28 | 17 | /** |
29 | 18 | * Execute the job. |
30 | 19 | * |
31 | 20 | * @return void |
32 | 21 | */ |
33 | | - public function handle() |
| 22 | + public function handle(GeneralSettings $settings) |
34 | 23 | { |
35 | | - if (File::exists(base_path().'/config.yml')) { |
36 | | - $config = Yaml::parseFile( |
37 | | - base_path().'/config.yml' |
38 | | - ); |
39 | | - } |
40 | | - |
41 | | - if (File::exists('/app/config.yml')) { |
42 | | - $config = Yaml::parseFile('/app/config.yml'); |
43 | | - } |
44 | | - |
45 | | - $speedtest = $config['speedtest']; |
46 | | - |
47 | | - $cron = new CronExpression($speedtest['schedule']); |
48 | | - |
49 | | - if ($cron->isDue() && $speedtest['enabled']) { |
50 | | - ExecSpeedtest::dispatch(speedtest: $speedtest, scheduled: true); |
| 24 | + $speedtest = [ |
| 25 | + 'enabled' => ! blank($settings->speedtest_schedule), |
| 26 | + 'schedule' => optional($settings)->speedtest_schedule, |
| 27 | + 'ookla_server_id' => optional($settings)->speedtest_server, |
| 28 | + ]; |
| 29 | + |
| 30 | + if ($speedtest['enabled']) { |
| 31 | + $cron = new CronExpression($speedtest['schedule']); |
| 32 | + |
| 33 | + if ($cron->isDue()) { |
| 34 | + ExecSpeedtest::dispatch(speedtest: $speedtest, scheduled: true); |
| 35 | + } |
51 | 36 | } |
52 | 37 | } |
53 | 38 | } |
0 commit comments