Skip to content
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

[Messenger][Process] add RunProcessMessage and RunProcessMessageHandler #49813

Merged
merged 1 commit into from
Jul 29, 2023

Conversation

kbond
Copy link
Member

@kbond kbond commented Mar 25, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets n/a
License MIT
Doc PR todo

When reviewing how I could replace my cron scheduler with symfony/scheduler, I realized I need a way to schedule processes.

Usage

use Symfony\Component\Process\Exception\RunProcessFailedException;
use Symfony\Component\Process\Messenger\RunProcessMessage;

try {
    $context = $bus->dispatch(new RunProcessMessage('something'));

    $context->exitCode; // int
    $context->output; // string
    $context->errorOutput; // string
catch(RunProcessFailedException $e) {
    $e->context->exitCode; // int
    $e->context->output; // string
    $e->context->errorOutput; // string
}

TODO:

  • wire up
  • tests

@carsonbot carsonbot added Status: Needs Review Feature Process RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Mar 25, 2023
@carsonbot carsonbot added this to the 6.3 milestone Mar 25, 2023
@carsonbot carsonbot changed the title [Process][RFC] add ExecuteProcess and ExecuteProcessHandler [Process] add ExecuteProcess and ExecuteProcessHandler Mar 25, 2023
@kbond
Copy link
Member Author

kbond commented Mar 25, 2023

Looking for feedback before proceeding further.

@kbond kbond changed the title [Process] add ExecuteProcess and ExecuteProcessHandler [Process][Messenger] add ExecuteProcess and ExecuteProcessHandler Mar 25, 2023
@carsonbot carsonbot changed the title [Process][Messenger] add ExecuteProcess and ExecuteProcessHandler [Messenger][Process] add ExecuteProcess and ExecuteProcessHandler Mar 25, 2023
src/Symfony/Component/Process/CHANGELOG.md Outdated Show resolved Hide resolved
src/Symfony/Component/Process/CHANGELOG.md Outdated Show resolved Hide resolved
src/Symfony/Component/Process/CHANGELOG.md Outdated Show resolved Hide resolved
@kbond kbond changed the title [Messenger][Process] add ExecuteProcess and ExecuteProcessHandler [Messenger][Process] add ProcessMessage and ProcessMessageHandler Mar 27, 2023
@kbond kbond force-pushed the messenger-process branch 3 times, most recently from 17b805b to 9a285c3 Compare March 27, 2023 14:50
@kbond kbond removed the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Mar 27, 2023
@kbond
Copy link
Member Author

kbond commented Mar 27, 2023

Pending a resolution to #49813 (comment), I think this is ready.

@OskarStark OskarStark requested a review from fabpot March 29, 2023 11:33
) {
}

public function __toString(): string
Copy link
Contributor

@ro0NL ro0NL Apr 24, 2023

Choose a reason for hiding this comment

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

generally what about just dumping payloads ($dump($messsage)) in CLI for -v[vv]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you explain this a bit more, I'm not understanding what you mean.

@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@kbond kbond changed the title [Messenger][Process] add ProcessMessage and ProcessMessageHandler [Messenger][Process] add RunProcessMessage and RunProcessMessageHandler Jul 28, 2023
@kbond
Copy link
Member Author

kbond commented Jul 28, 2023

I've renamed the classes per the review.

I've also added a RunProcessContext that's returned from the handler and a RunProcessFailedException that's thrown by the handler on failure. These will allow the message/exception to be serialized while still giving access to the result.

@kbond
Copy link
Member Author

kbond commented Jul 28, 2023

Comments addressed and PR description updated to show usage.

@fabpot
Copy link
Member

fabpot commented Jul 29, 2023

Thank you @kbond.

@fabpot fabpot merged commit 70768ff into symfony:6.4 Jul 29, 2023
6 of 9 checks passed
fabpot added a commit that referenced this pull request Jul 30, 2023
…ommandMessageHandler` (kbond)

This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[Console][Messenger] add `RunCommandMessage` and `RunCommandMessageHandler`

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | n/a
| License       | MIT
| Doc PR        | todo

Similar to #49813, when using the scheduler it could be useful to execute commands.

## Usage

```php
use Symfony\Component\Console\Exception\RunCommandFailedException;
use Symfony\Component\Console\Messenger\RunCommandMessage;

try {
    $context = $bus->dispatch(new RunCommandMessage('my:command'));

    $context->output; // string - output of command
    $context->exitCode; // int - the exit code
catch(RunCommandFailedException $e) { // if exit code is non-zero or command threw exception
    $e->context->output; // string - output of command
    $e->context->exitCode; // int - the exit code
    $e->getPrevious(); // null|\Throwable exception command threw if applicable
}

// "never" fail
$context = $bus->dispatch(new RunCommandMessage('my:command', throwOnNonSuccess: false, catchExceptions: true));
```

TODO:
- [x] wire up
- [x] tests

Commits
-------

dd5b0b7 [Console][Messenger] add `RunCommandMessage` and `RunCommandMessageHandler`
This was referenced Oct 21, 2023
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.

None yet

7 participants