-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[8.x] Add JobQueued event #32894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Add JobQueued event #32894
Conversation
Change-Id: I3baa202c3054617c330c9cb76e84f0b02269dc09
@taylorotwell To be sure, following your comment (#32881 (comment)) my next step shall be to refactor:
to
|
Is there a big reason you didn't fire event from Queue::push? Why fire it in Bus? |
At the beginning I put it in Now I see the method: Now why not
I note now that the If you want this to be implemented in |
Yeah there is generally some inconsistency here. The other job events fire for bulk queued jobs but this doesn't. |
Fine, then I will revert my changes and go on Illuminate\Queue\Queue. I will add both For the event dispatch I will use the container the same way you did in SyncQueue class. |
Change-Id: Ic7aa4166f05f77f7d85010d8ea57195b0870fdf6
@taylorotwell My latest commit (10022f6) is a revert from my first implementation with the logic being moved to queue as you asked. To track the queued job we always need the Due to this, calling a parent implementation was not possible in a clean way, so to avoid code duplication I made the choice to reduce the visibility and rename all concrete This way they act as proxy to the old method and make sure the event is dispatched with the returned This commit does not change any tests (so they fail), let me know is this solution is valid for you, then I will try to go trough them. |
Change-Id: I0c11cd3f6cabce3ae83110396b706fdf34060c21
Change-Id: I5808e66bf263cb15c192439ae18cfe8f7d088462
I think you would have better luck just using the base queue createPayload() method to fire the event. All the queue drivers call it during push and during bulk. |
Sure However does that means that a function named Doing it this way will sure reduce the amount of changed code. But as the current solution, no interface is changed and the same tests using mocks will fail. So I'm not sure about the benefits of using createPayload(). |
Going to close this for now as I don't want to make this many changes to support it. |
Sure, maybe refactoring the inheritance of This would help moving functions like createStringPayload(), createObjectPayload(), bulk(), raiseJobQueuedEvent() out of the engine themselves... In the meanwhile if you want this feature to be done inside |
(Follows: laravel/framework#32894)
This PR aims to add a new
JobQueued
event dispatched when a job is added to a queue.The main reason for this is to complete the existing events list:
JobProcessing
,JobProcessed
,JobFailed
andJobExceptionOccurred
which let users track the jobs.Looking for packages or tutorials to track queued job status will give for example: https://github.com/imTigger/laravel-job-status or https://blog.rafter.app/tracking-queued-job-chains-in-laravel/ .
In both cases the trick is made by creating the tracking record to the database inside the job's constructor.
Having a
JobQueue
event aims to remove this DB call from the job's constructor.So to track a job a simple
EventSubscriber
class could be created as:--
Following: #32881