forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestConnectionJob.php
More file actions
67 lines (54 loc) · 1.67 KB
/
TestConnectionJob.php
File metadata and controls
67 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace App\Jobs\Influxdb\v2;
use App\Actions\Influxdb\v2\CreateClient;
use App\Models\User;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
use InfluxDB2\ApiException;
use InfluxDB2\Point;
class TestConnectionJob implements ShouldQueue
{
use Queueable;
/**
* Create a new job instance.
*/
public function __construct(
public User $user,
) {}
/**
* Execute the job.
*/
public function handle(): void
{
$client = CreateClient::run();
$writeApi = $client->createWriteApi();
$point = Point::measurement('speedtest')
->addTag('service', 'faker')
->addField('download', (int) 420)
->addField('upload', (int) 69)
->addField('ping', (float) 4.321)
->time(time());
try {
$writeApi->write($point);
} catch (ApiException $e) {
Log::error('Failed to write test data to Influxdb.', [
'error' => $e->getMessage(),
]);
Notification::make()
->title('Influxdb test failed')
->body('Check the logs for more details.')
->danger()
->sendToDatabase($this->user);
$writeApi->close();
return;
}
$writeApi->close();
Notification::make()
->title('Successfully sent test data to Influxdb')
->body('Test data has been sent to InfluxDB, check if the data was received.')
->success()
->sendToDatabase($this->user);
}
}