Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Scheduler] Add MessageHandler result to thePostRunEvent#58546

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

bartholdbos
Copy link
Contributor

@bartholdbosbartholdbos commentedOct 11, 2024
edited by fabpot
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
Issues
LicenseMIT

This PR will add the result of a MessageHandler to the PostRunEvent of the Scheduler Component. This can be used for example for retrieving the output of a RunCommandMessage scheduled by the scheduler component.

<?phpnamespace App\Service;use Symfony\Component\Console\Messenger\RunCommandMessage;use Symfony\Component\Scheduler\Attribute\AsSchedule;use Symfony\Component\Scheduler\RecurringMessage;use Symfony\Component\Scheduler\Schedule;use Symfony\Component\Scheduler\ScheduleProviderInterface;#[AsSchedule]class ScheduleProvider implements ScheduleProviderInterface{    public function getSchedule(): Schedule    {        $schedule = new Schedule();        $schedule->add(RecurringMessage::cron('* * * * *', new RunCommandMessage('about')));        return $schedule;    }}
<?phpnamespace App\EventListener;use Symfony\Component\Console\Messenger\RunCommandContext;use Symfony\Component\EventDispatcher\Attribute\AsEventListener;use Symfony\Component\Scheduler\Event\PostRunEvent;#[AsEventListener(event: PostRunEvent::class, method: 'onMessage')]class SchedulerListener{    public function onMessage(PostRunEvent $event): void    {        $result = $event->getResult();        if ($result instanceof RunCommandContext) {            echo $result->output; //Log or store output somewhere        }    }}

@slutsky
Copy link

slutsky commentedOct 11, 2024
edited
Loading

How does it work if the handler result type is "never"?

I think It's better to use a message to transfer result. Possible to use a setter to add a result to the message inside a handler.

@bartholdbos
Copy link
ContributorAuthor

How does it work if the handler result type is "never"?

I think It's better to use a message to transfer result. Possible to use a setter to add a result to the message inside a handler.

If the MessageHandler does never return the $result value will be null. If the messagehandler is not in your own control(for instance RunCommandMessageHandler) it is not possible to use a setter to set the result to the message from the handler. The HandledStamp already collects the result of the message handler. This change will only allow you to use this result in the scheduler component as well.

@bartholdbosbartholdbosforce-pushed thescheduler-post-run-event-result branch from1705445 to4e56ad4CompareOctober 18, 2024 09:46
@bartholdbos
Copy link
ContributorAuthor

@kbond Could you take a look at this maybe?

Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

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

I think this makes sense.@alli83, have any thoughts?

@bartholdbosbartholdbosforce-pushed thescheduler-post-run-event-result branch from03dceb0 to468c02dCompareOctober 25, 2024 13:34
@bartholdbos
Copy link
ContributorAuthor

bartholdbos commentedOct 25, 2024
edited
Loading

Thanks for the reply. I have also changed theServiceCallMessageHandler to return it's result. This way thePostRunEvent result would also be available forAsPeriodicTask andAsCronTask. Also when usingRedispatchMessage with async:// transport configured while developing I noticed the result didn't come through so I also returned the result in theRedispatchMessageHandler. Let me know what you think of these latest changes.

@bartholdbosbartholdbosforce-pushed thescheduler-post-run-event-result branch from468c02d to959b270CompareOctober 26, 2024 10:04
@bartholdbos
Copy link
ContributorAuthor

@alli83 or@kbond could you review this maybe?

@alli83
Copy link
Contributor

alli83 commentedOct 29, 2024
edited
Loading

Retrieving the result could indeed be interesting e.g depending on the outcome, we might decide whether to continue or stop.
However, regarding the logging example, imho, I wonder if it’s really necessary to handle it in the listener rather than directly within the handler.

Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

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

I'm good with this feature. Can you add an entry to the changelog?

Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

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

7.2 is in feature freeze so this will likely not make it until 7.3.

bartholdbos reacted with thumbs up emoji
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@bartholdbosbartholdbosforce-pushed thescheduler-post-run-event-result branch from268e589 to05fe4a3CompareDecember 13, 2024 10:02
@bartholdbos
Copy link
ContributorAuthor

@kbond I have rebased the branch on 7.3

Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

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

Looks good!

@bartholdbos, would you like to try updating the test? I was thinkinghere, instead of setting the props to true, set them to the event object and then assert on them in the test. If not, no worries, I can add after merge.

@bartholdbos
Copy link
ContributorAuthor

@kbond Sure, I have updated the test to use the event object instead of the booleans. It can now assert on properties that are in the event, is this what you meant?

Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

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

Yes, that looks great!

@bartholdbos
Copy link
ContributorAuthor

Thanks for the review@kbond! I think it's ready on my side, is another review required or is it ready for merging by you/somebody else?

@kbond
Copy link
Member

Just need to wait for another core team member approval.

@bartholdbos
Copy link
ContributorAuthor

@fabpot Could you maybe take a look at this?

@OskarStarkOskarStark changed the title[Scheduler] Add MessageHandler result to the PostRunEvent[Scheduler] Add MessageHandler result to thePostRunEventJan 30, 2025
@kbond
Copy link
Member

@bartholdbos, since this has been approved, it'll likely get approved by another core member and merged closer to the 7.3 feature freeze.

@fabpotfabpotforce-pushed thescheduler-post-run-event-result branch from3e9c00b to306eeb6CompareFebruary 7, 2025 08:23
@fabpot
Copy link
Member

Thank you@bartholdbos.

@fabpotfabpot merged commit201747b intosymfony:7.3Feb 7, 2025
8 of 9 checks passed
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot approved these changes

@kbondkbondkbond approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

6 participants
@bartholdbos@slutsky@alli83@kbond@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp