Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
monitoring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cylab
monitoring
Commits
cb7aea6c
Commit
cb7aea6c
authored
1 year ago
by
Thibault Debatty
Browse files
Options
Downloads
Patches
Plain Diff
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
1 year ago
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/AgentScheduler.php
+3
-8
3 additions, 8 deletions
app/AgentScheduler.php
app/Jobs/RunAgent.php
+59
-0
59 additions, 0 deletions
app/Jobs/RunAgent.php
with
62 additions
and
8 deletions
app/AgentScheduler.php
+
3
−
8
View file @
cb7aea6c
...
...
@@ -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
);
}
}
}
This diff is collapsed.
Click to expand it.
app/Jobs/RunAgent.php
0 → 100644
+
59
−
0
View file @
cb7aea6c
<?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
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment