Skip to content

[Messenger] Add WorkerStoppedEvent #31282

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

Merged
merged 1 commit into from
Apr 28, 2019
Merged

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Apr 26, 2019

Q A
Branch? 4.3
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

In 4.2, one was able to decorate a transport and hook into TransportInterface::stop() to perform some business tasks when the messenger:consume process gets killed.
In 4.3 the stop() logic has been moved to Worker which cannot be decorated when used via messenger:consume.
This PR adds a marker event dispatched when the worker is stopped to provide the same capability.

Briefly discussed with @weaverryan.
My use case:
I have a temporary CSV file locally which grows while consuming jobs.
This file is uploaded to AWS S3 and squashed once a while (every 5minutes). It is also uploaded when the messenger:consume process gets stopped (to store the remaining lines).
For the former (time-based upload), I can listen on WorkflowMessageHandledEvent to make the upload happens in case the 5 minutes delay is elapsed. This solves the latter.

@chalasr chalasr force-pushed the messenger-worker-stop branch from 4733c22 to 0e7898b Compare April 27, 2019 18:22
Copy link
Contributor

@sroze sroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

@sroze
Copy link
Contributor

sroze commented Apr 28, 2019

Thank you @chalasr.

@sroze sroze merged commit 0e7898b into symfony:master Apr 28, 2019
sroze added a commit that referenced this pull request Apr 28, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] Add WorkerStoppedEvent

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

In 4.2, one was able to decorate a transport and hook into `TransportInterface::stop()` to perform some business tasks when the `messenger:consume` process gets killed.
In 4.3 the `stop()` logic has been moved to `Worker` which cannot be decorated when used via `messenger:consume`.
This PR adds a marker event dispatched when the worker is stopped to provide the same capability.

Briefly discussed with @weaverryan.
My use case:
I have a temporary CSV file locally which grows while consuming jobs.
This file is uploaded to AWS S3 and squashed once a while (every 5minutes). It is also uploaded when the `messenger:consume` process gets stopped (to store the remaining lines).
For the former (time-based upload), I can listen on `WorkflowMessageHandledEvent` to make the upload happens in case the 5 minutes delay is elapsed. This solves the latter.

Commits
-------

0e7898b [Messenger] Add WorkerStoppedEvent
@chalasr chalasr deleted the messenger-worker-stop branch April 28, 2019 14:00
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants