Xboard/app/Jobs/TrafficFetchJob.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2023-11-17 01:44:01 -05:00
<?php
namespace App\Jobs;
use App\Models\User;
2023-11-17 01:44:01 -05:00
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class TrafficFetchJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2025-01-06 12:20:11 -05:00
protected $data;
2023-11-17 01:44:01 -05:00
protected $server;
protected $protocol;
2025-01-06 12:20:11 -05:00
protected $timestamp;
public $tries = 1;
public $timeout = 20;
2023-11-17 01:44:01 -05:00
/**
* Create a new job instance.
*
* @return void
*/
2025-01-06 12:20:11 -05:00
public function __construct(array $server, array $data, $protocol, int $timestamp)
2023-11-17 01:44:01 -05:00
{
$this->onQueue('traffic_fetch');
$this->server = $server;
2025-01-06 12:20:11 -05:00
$this->data = $data;
2023-11-17 01:44:01 -05:00
$this->protocol = $protocol;
2025-01-06 12:20:11 -05:00
$this->timestamp = $timestamp;
2023-11-17 01:44:01 -05:00
}
2025-01-06 12:20:11 -05:00
public function handle(): void
2023-11-17 01:44:01 -05:00
{
2025-01-06 12:20:11 -05:00
foreach ($this->data as $uid => $v) {
User::where('id', $uid)
->incrementEach(
[
'u' => $v[0] * $this->server['rate'],
'd' => $v[1] * $this->server['rate'],
],
['t' => time()]
);
}
2023-11-17 01:44:01 -05:00
}
2025-01-06 12:20:11 -05:00
}