Skip to content

[13.x] Allow passing scheduled Event in callbacks#60144

Merged
taylorotwell merged 3 commits into
laravel:13.xfrom
cosmastech:allow-passing-event-to-after
May 16, 2026
Merged

[13.x] Allow passing scheduled Event in callbacks#60144
taylorotwell merged 3 commits into
laravel:13.xfrom
cosmastech:allow-passing-event-to-after

Conversation

@cosmastech
Copy link
Copy Markdown
Contributor

@cosmastech cosmastech commented May 16, 2026

This would be a lovely pairing with #60133.

Background

Our team realized this week that some of our critical scheduled commands were dying on the vine due to OOM. It would be helpful to have standardized logs write "Command {$event->command} started|completed|failed" in before and after hooks. Given that we have so many scheduled commands, it's a bit tedious to write the callbacks for all of them. Also... we have to remember to do it going forward 🫠

What this does

Allows userland to typehint a callback with Event $event as a parameter, and pass $this to it.

Example

Schedule::command('delete-expired-invites')
    ->hourly()
    ->before(fn (Event $event) => Log::info("Starting {$event->command}")
    ->after(fn (Stringable $output, Event $event) => Log::info("Completed {$event->command} with output:\n$output"));

@cosmastech
Copy link
Copy Markdown
Contributor Author

Looks like test failure should be resolved by #60143

@cosmastech cosmastech changed the title [13.x] Allowing receiving scheduled Event in callbacks [13.x] Allow passing scheduled Event in callbacks May 16, 2026
@taylorotwell taylorotwell merged commit b6d05cc into laravel:13.x May 16, 2026
36 of 52 checks passed
@cosmastech cosmastech deleted the allow-passing-event-to-after branch May 17, 2026 00:24
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.

2 participants