|
@@ -12,7 +12,11 @@ use Illuminate\Queue\SerializesModels;
|
|
class StatServerJob implements ShouldQueue
|
|
class StatServerJob implements ShouldQueue
|
|
{
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
- protected $statistic;
|
|
|
|
|
|
+ protected $u;
|
|
|
|
+ protected $d;
|
|
|
|
+ protected $server;
|
|
|
|
+ protected $protocol;
|
|
|
|
+ protected $recordType;
|
|
|
|
|
|
public $tries = 3;
|
|
public $tries = 3;
|
|
public $timeout = 60;
|
|
public $timeout = 60;
|
|
@@ -22,10 +26,14 @@ class StatServerJob implements ShouldQueue
|
|
*
|
|
*
|
|
* @return void
|
|
* @return void
|
|
*/
|
|
*/
|
|
- public function __construct(array $statistic)
|
|
|
|
|
|
+ public function __construct($u, $d, $server, $protocol, $recordType = 'd')
|
|
{
|
|
{
|
|
- $this->onQueue('stat_server');
|
|
|
|
- $this->statistic = $statistic;
|
|
|
|
|
|
+ $this->onQueue('stat');
|
|
|
|
+ $this->u = $u;
|
|
|
|
+ $this->d = $d;
|
|
|
|
+ $this->server = $server;
|
|
|
|
+ $this->protocol = $protocol;
|
|
|
|
+ $this->recordType = $recordType;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -35,18 +43,32 @@ class StatServerJob implements ShouldQueue
|
|
*/
|
|
*/
|
|
public function handle()
|
|
public function handle()
|
|
{
|
|
{
|
|
- $statistic = $this->statistic;
|
|
|
|
- $data = StatServer::where('record_at', $statistic['record_at'])
|
|
|
|
- ->where('server_id', $statistic['server_id'])
|
|
|
|
|
|
+ $recordAt = strtotime(date('Y-m-d'));
|
|
|
|
+ if ($this->recordType === 'm') {
|
|
|
|
+ //
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $data = StatServer::where('record_at', $recordAt)
|
|
|
|
+ ->where('server_id', $this->server->id)
|
|
->first();
|
|
->first();
|
|
if ($data) {
|
|
if ($data) {
|
|
try {
|
|
try {
|
|
- $data->update($statistic);
|
|
|
|
|
|
+ $data->update([
|
|
|
|
+ 'u' => $data['u'] + $this->u,
|
|
|
|
+ 'd' => $data['d'] + $this->d
|
|
|
|
+ ]);
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
abort(500, '节点统计数据更新失败');
|
|
abort(500, '节点统计数据更新失败');
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (!StatServer::create($statistic)) {
|
|
|
|
|
|
+ if (!StatServer::create([
|
|
|
|
+ 'server_id' => $this->server->id,
|
|
|
|
+ 'server_type' => $this->protocol,
|
|
|
|
+ 'u' => $this->u,
|
|
|
|
+ 'd' => $this->d,
|
|
|
|
+ 'record_type' => $this->recordType,
|
|
|
|
+ 'record_at' => $recordAt
|
|
|
|
+ ])) {
|
|
abort(500, '节点统计数据创建失败');
|
|
abort(500, '节点统计数据创建失败');
|
|
}
|
|
}
|
|
}
|
|
}
|