File tree Expand file tree Collapse file tree 7 files changed +77
-0
lines changed
Expand file tree Collapse file tree 7 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -288,6 +288,27 @@ public function boot(): void
288288
289289Want to keep the dashboard public but still record jobs? Either return ` true ` from the gate even for guests, or set ` VANTAGE_AUTH_ENABLED=false ` .
290290
291+ ### Exclude Jobs from Monitoring
292+
293+ if you want to exclude some jobs from being tracked by Vantage, you can add them to the ` exclude_jobs ` config array:
294+
295+ ``` php
296+ 'exclude_jobs' => [
297+ App\Jobs\SomeNoisyJob::class,
298+ ],
299+ ```
300+
301+ Or implement the 'ShouldNotBeTracked' class.
302+
303+ ``` php
304+ use HoudaSlassi\Vantage\Contracts\ShouldNotBeTracked;
305+
306+ class MyNoisyJob implements ShouldQueue, ShouldNotBeTracked
307+ {
308+ public function handle(): void { ... }
309+ }
310+ ```
311+
291312## Testing
292313
293314### Using the Model Factory
Original file line number Diff line number Diff line change 170170 'logging ' => [
171171 'enabled ' => env ('VANTAGE_LOGGING_ENABLED ' , true ),
172172 ],
173+
174+ /*
175+ |--------------------------------------------------------------------------
176+ | Excluded Jobs
177+ |--------------------------------------------------------------------------
178+ | Job classes listed here will not be recorded by Vantage.
179+ | You can also implement ShouldNotBeTracked on any job class.
180+ */
181+ 'exclude_jobs ' => [
182+ // App\Jobs\SomeNoisyJob::class,
183+ ],
173184];
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace HoudaSlassi \Vantage \Contracts ;
6+
7+ interface ShouldNotBeTracked {}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace HoudaSlassi \Vantage \Listeners ;
6+
7+ use HoudaSlassi \Vantage \Contracts \ShouldNotBeTracked ;
8+
9+ trait ChecksJobExclusion
10+ {
11+ protected function isExcluded (string $ jobClass ): bool
12+ {
13+ // Check interface
14+ if (is_a ($ jobClass , ShouldNotBeTracked::class, true )) {
15+ return true ;
16+ }
17+
18+ // Check config exclude list
19+ $ excluded = config ('vantage.exclude_jobs ' , []);
20+
21+ return in_array ($ jobClass , $ excluded , true );
22+ }
23+ }
Original file line number Diff line number Diff line change 1515
1616class RecordJobFailure
1717{
18+ use ChecksJobExclusion;
1819 use ExtractsRetryOf;
1920
2021 public function handle (JobFailed $ event ): void
@@ -24,6 +25,10 @@ public function handle(JobFailed $event): void
2425 return ;
2526 }
2627
28+ if ($ this ->isExcluded ($ event ->job ->resolveName ())) {
29+ return ;
30+ }
31+
2732 $ uuid = $ this ->bestUuid ($ event );
2833 $ jobClass = $ this ->jobClass ($ event );
2934 $ queue = $ event ->job ->getQueue ();
Original file line number Diff line number Diff line change 1313
1414class RecordJobStart
1515{
16+ use ChecksJobExclusion;
1617 use ExtractsRetryOf;
1718
1819 public function handle (JobProcessing $ event ): void
@@ -22,6 +23,10 @@ public function handle(JobProcessing $event): void
2223 return ;
2324 }
2425
26+ if ($ this ->isExcluded ($ event ->job ->resolveName ())) {
27+ return ;
28+ }
29+
2530 $ uuid = $ this ->bestUuid ($ event );
2631
2732 // Telemetry config & sampling
Original file line number Diff line number Diff line change 1212
1313class RecordJobSuccess
1414{
15+ use ChecksJobExclusion;
1516 use ExtractsRetryOf;
1617
1718 public function handle (JobProcessed $ event ): void
@@ -21,6 +22,10 @@ public function handle(JobProcessed $event): void
2122 return ;
2223 }
2324
25+ if ($ this ->isExcluded ($ event ->job ->resolveName ())) {
26+ return ;
27+ }
28+
2429 // Some jobs (like rate-limited ones) are "processed" only to be released immediately.
2530 // Laravel exposes helpers to detect this so we don't count them as successful runs.
2631 if (method_exists ($ event ->job , 'isReleased ' ) && $ event ->job ->isReleased ()) {
You can’t perform that action at this time.
0 commit comments