Skip to content
Snippets Groups Projects
Commit cb7aea6c authored by Thibault Debatty's avatar Thibault Debatty
Browse files

use job to run agents in the background

parent d3cc409a
No related branches found
No related tags found
No related merge requests found
Pipeline #13327 failed
......@@ -2,6 +2,8 @@
namespace App;
use App\Jobs\RunAgent;
use Illuminate\Support\Facades\File;
use Illuminate\Support\LazyCollection;
use Symfony\Component\Finder\SplFileInfo;
......@@ -102,7 +104,6 @@ class AgentScheduler
public function notify(Record $record)
{
$server_info = $record->server->info();
$trigger_label = $record->label;
if (! isset($this->triggers[$trigger_label])) {
......@@ -115,13 +116,7 @@ class AgentScheduler
}
foreach ($this->triggers[$trigger_label] as $agent) {
/** @var Sensor $agent */
$report = $agent->analyze($records, $server_info);
$report->time = time();
$report->server_id = $record->server_id;
$report->label = $agent->config()->label;
$report->save();
RunAgent::dispatch($agent, $record->server);
}
}
}
<?php
namespace App\Jobs;
use App\Sensor;
use App\Server;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class RunAgent implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
*
* @var Sensor
*/
public $agent;
/**
*
* @var Server
*/
public $server;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Sensor $agent, Server $server)
{
$this->agent = $agent;
$this->server = $server;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$trigger_label = $this->agent->config()->trigger_label;
$records = $this->server->lastRecords($trigger_label);
/** @var Sensor $agent */
$report = $this->agent->analyze($records, $this->server->info());
$report->time = time();
$report->server_id = $this->server->id;
$report->label = $this->agent->config()->label;
$report->save();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment