Skip to content

[12.x] Add support for expected exit codes in the scheduler #56329

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

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
from

Conversation

netpok
Copy link
Contributor

@netpok netpok commented Jul 17, 2025

Description

Scheduled command return code checking was introduced in #55624, however sometimes non 0 return codes can also be considered successful (especially when running external programs with the exec call)

Solution

This PR introduces two new methods on the scheduled event:

  • allowExitCode which can be used to allow additional exit code(s) for the command
  • allowFailures which can be used to accept all exit codes

Additionally a new exception is also introduced for the unexpected exit codes so it could be handled in the exception handler.

Examples

// Considered successful if exit code is 0 or 1
$schedule->command('app:first')->daily()->allowExitCode(1);

// Considered successful if exit code is 0, 2 or 12
$schedule->command('app:first')->daily()->allowExitCode([2, 12]);

// All exit codes considered successful 
$schedule->command('app:first')->daily()->allowFailure();

Backwards compatibility

  • Without explicitly allowing exit codes the functionality is the same.
  • The new exception extends RuntimeException, and uses the same message so any existing exception handling should also work after this PR

If required I can also make a PR for the docs after this is merged. Please also let me know if any naming should be changed or any type hints should be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant