Skip to content

Commit 08f38b1

Browse files
committed
wip
1 parent 7aba92e commit 08f38b1

File tree

4 files changed

+33
-50
lines changed

4 files changed

+33
-50
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ use Illuminate\Queue\SerializesModels;
5656
use Illuminate\Queue\InteractsWithQueue;
5757
use Illuminate\Contracts\Queue\ShouldQueue;
5858
use Illuminate\Foundation\Bus\Dispatchable;
59+
5960
use romanzipp\QueueMonitor\Traits\IsMonitored; // <---
61+
use romanzipp\QueueMonitor\Contracts\MonitoredJobContract; // <---
6062

61-
class ExampleJob implements ShouldQueue
63+
class ExampleJob implements ShouldQueue, MonitoredJobContract
6264
{
6365
use Dispatchable;
6466
use InteractsWithQueue;

src/Providers/QueueMonitorProvider.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ public function boot(): void
9595
$queueManager->exceptionOccurred(static function (QueueEvents\JobExceptionOccurred $event) {
9696
QueueMonitor::handleJobExceptionOccurred($event);
9797
});
98+
99+
100+
$this->app['events']->listen([
101+
QueueEvents\JobExceptionOccurred::class,
102+
QueueEvents\JobFailed::class,
103+
QueueEvents\JobPopped::class,
104+
QueueEvents\JobPopping::class,
105+
QueueEvents\JobProcessed::class,
106+
QueueEvents\JobProcessing::class,
107+
QueueEvents\JobQueued::class,
108+
QueueEvents\JobQueueing::class,
109+
QueueEvents\JobReleasedAfterException::class,
110+
QueueEvents\JobRetryRequested::class,
111+
QueueEvents\JobTimedOut::class,
112+
QueueEvents\Looping::class,
113+
QueueEvents\QueueBusy::class,
114+
QueueEvents\WorkerStopping::class,
115+
], function ($event) {
116+
#dump(get_class($event));
117+
});
98118
}
99119

100120
/**

src/Services/QueueMonitor.php

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
use Illuminate\Container\Container;
66
use Illuminate\Contracts\Encryption\Encrypter;
77
use Illuminate\Contracts\Queue\Job as JobContract;
8-
use Illuminate\Queue\Events\JobExceptionOccurred;
9-
use Illuminate\Queue\Events\JobFailed;
10-
use Illuminate\Queue\Events\JobProcessed;
11-
use Illuminate\Queue\Events\JobProcessing;
12-
use Illuminate\Queue\Events\JobQueued;
8+
use Illuminate\Queue\Events as QueueEvents;
139
use Illuminate\Support\Carbon;
1410
use romanzipp\QueueMonitor\Enums\MonitorStatus;
1511
use romanzipp\QueueMonitor\Models\Contracts\MonitorContract;
1612
use romanzipp\QueueMonitor\Traits\IsMonitored;
1713

1814
class QueueMonitor
1915
{
20-
private const TIMESTAMP_EXACT_FORMAT = 'Y-m-d H:i:s.u';
16+
private const string TIMESTAMP_EXACT_FORMAT = 'Y-m-d H:i:s.u';
2117

2218
public static string $model;
2319

@@ -31,14 +27,7 @@ public static function getModel(): MonitorContract
3127
return new self::$model();
3228
}
3329

34-
/**
35-
* Handle Job Queued.
36-
*
37-
* @param JobQueued $event
38-
*
39-
* @return void
40-
*/
41-
public static function handleJobQueued(JobQueued $event): void
30+
public static function handleJobQueued(QueueEvents\JobQueued $event): void
4231
{
4332
self::jobQueued($event);
4433
}
@@ -53,50 +42,22 @@ public static function handleJobPushed($event): void
5342
self::jobPushed($event);
5443
}
5544

56-
/**
57-
* Handle Job Processing.
58-
*
59-
* @param JobProcessing $event
60-
*
61-
* @return void
62-
*/
63-
public static function handleJobProcessing(JobProcessing $event): void
45+
public static function handleJobProcessing(QueueEvents\JobProcessing $event): void
6446
{
6547
self::jobStarted($event->job);
6648
}
6749

68-
/**
69-
* Handle Job Processed.
70-
*
71-
* @param JobProcessed $event
72-
*
73-
* @return void
74-
*/
75-
public static function handleJobProcessed(JobProcessed $event): void
50+
public static function handleJobProcessed(QueueEvents\JobProcessed $event): void
7651
{
7752
self::jobFinished($event->job, MonitorStatus::SUCCEEDED);
7853
}
7954

80-
/**
81-
* Handle Job Failing.
82-
*
83-
* @param JobFailed $event
84-
*
85-
* @return void
86-
*/
87-
public static function handleJobFailed(JobFailed $event): void
55+
public static function handleJobFailed(QueueEvents\JobFailed $event): void
8856
{
8957
self::jobFinished($event->job, MonitorStatus::FAILED, $event->exception);
9058
}
9159

92-
/**
93-
* Handle Job Exception Occurred.
94-
*
95-
* @param JobExceptionOccurred $event
96-
*
97-
* @return void
98-
*/
99-
public static function handleJobExceptionOccurred(JobExceptionOccurred $event): void
60+
public static function handleJobExceptionOccurred(QueueEvents\JobExceptionOccurred $event): void
10061
{
10162
self::jobFinished($event->job, MonitorStatus::FAILED, $event->exception);
10263
}
@@ -120,11 +81,11 @@ public static function getJobId(JobContract $job): string
12081
/**
12182
* Start Queue Monitoring for Job.
12283
*
123-
* @param JobQueued $event
84+
* @param QueueEvents\JobQueued $event
12485
*
12586
* @return void
12687
*/
127-
protected static function jobQueued(JobQueued $event): void
88+
protected static function jobQueued(QueueEvents\JobQueued $event): void
12889
{
12990
if ( ! self::shouldBeMonitored($event->job)) {
13091
return;

src/Traits/IsMonitored.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trait IsMonitored
2222
*
2323
* @var int
2424
*/
25-
private ?int $progressCurrentChunk = 0;
25+
private int $progressCurrentChunk = 0;
2626

2727
/**
2828
* Update progress.

0 commit comments

Comments
 (0)