Skip to content

Commit 5c4b53b

Browse files
authored
[Chore] Refactored InfluxDBv2 data listener (alexjustesen#1272)
1 parent a866e85 commit 5c4b53b

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

app/Jobs/SendDataToInfluxDbV2.php renamed to app/Jobs/InfluxDBv2/WriteCompletedSpeedtest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace App\Jobs;
3+
namespace App\Jobs\InfluxDBv2;
44

55
use App\Models\Result;
66
use App\Settings\InfluxDbSettings;
@@ -12,24 +12,19 @@
1212
use Illuminate\Support\Facades\Log;
1313
use InfluxDB2\Client;
1414

15-
class SendDataToInfluxDbV2 implements ShouldQueue
15+
class WriteCompletedSpeedtest implements ShouldQueue
1616
{
1717
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
1818

19-
public $result;
20-
21-
public $settings;
22-
2319
/**
2420
* Create a new job instance.
2521
*
2622
* @return void
2723
*/
28-
public function __construct(Result $result, InfluxDbSettings $settings)
29-
{
30-
$this->result = $result;
31-
32-
$this->settings = $settings;
24+
public function __construct(
25+
public Result $result,
26+
public InfluxDbSettings $settings,
27+
) {
3328
}
3429

3530
/**

app/Listeners/Data/InfluxDb2Listener.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,20 @@
33
namespace App\Listeners\Data;
44

55
use App\Events\SpeedtestCompleted;
6-
use App\Jobs\SendDataToInfluxDbV2;
6+
use App\Jobs\InfluxDBv2\WriteCompletedSpeedtest;
77
use App\Settings\InfluxDbSettings;
8-
use Illuminate\Contracts\Queue\ShouldQueue;
98

10-
class InfluxDb2Listener implements ShouldQueue
9+
class InfluxDb2Listener
1110
{
12-
public $influxDbSettings;
13-
14-
/**
15-
* Create the event listener.
16-
*
17-
* @return void
18-
*/
19-
public function __construct()
20-
{
21-
$this->influxDbSettings = new (InfluxDbSettings::class);
22-
}
23-
2411
/**
2512
* Handle the event.
2613
*/
2714
public function handle(SpeedtestCompleted $event): void
2815
{
29-
if ($this->influxDbSettings->v2_enabled) {
30-
SendDataToInfluxDbV2::dispatch($event->result, $this->influxDbSettings);
16+
$influxSettings = new InfluxDbSettings();
17+
18+
if ($influxSettings->v2_enabled) {
19+
WriteCompletedSpeedtest::dispatch($event->result, $influxSettings);
3120
}
3221
}
3322
}

0 commit comments

Comments
 (0)