Skip to content

Commit

Permalink
[Chore] Refactored InfluxDBv2 data listener (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Mar 1, 2024
1 parent a866e85 commit 5c4b53b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Jobs;
namespace App\Jobs\InfluxDBv2;

use App\Models\Result;
use App\Settings\InfluxDbSettings;
Expand All @@ -12,24 +12,19 @@
use Illuminate\Support\Facades\Log;
use InfluxDB2\Client;

class SendDataToInfluxDbV2 implements ShouldQueue
class WriteCompletedSpeedtest implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $result;

public $settings;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Result $result, InfluxDbSettings $settings)
{
$this->result = $result;

$this->settings = $settings;
public function __construct(
public Result $result,
public InfluxDbSettings $settings,
) {
}

/**
Expand Down
23 changes: 6 additions & 17 deletions app/Listeners/Data/InfluxDb2Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@
namespace App\Listeners\Data;

use App\Events\SpeedtestCompleted;
use App\Jobs\SendDataToInfluxDbV2;
use App\Jobs\InfluxDBv2\WriteCompletedSpeedtest;
use App\Settings\InfluxDbSettings;
use Illuminate\Contracts\Queue\ShouldQueue;

class InfluxDb2Listener implements ShouldQueue
class InfluxDb2Listener
{
public $influxDbSettings;

/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
$this->influxDbSettings = new (InfluxDbSettings::class);
}

/**
* Handle the event.
*/
public function handle(SpeedtestCompleted $event): void
{
if ($this->influxDbSettings->v2_enabled) {
SendDataToInfluxDbV2::dispatch($event->result, $this->influxDbSettings);
$influxSettings = new InfluxDbSettings();

if ($influxSettings->v2_enabled) {
WriteCompletedSpeedtest::dispatch($event->result, $influxSettings);
}
}
}

0 comments on commit 5c4b53b

Please sign in to comment.