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

Task specific onError callback? #281

Open
Notmissleo opened this issue Jan 9, 2020 · 1 comment
Open

Task specific onError callback? #281

Notmissleo opened this issue Jan 9, 2020 · 1 comment
Milestone

Comments

@Notmissleo
Copy link

Notmissleo commented Jan 9, 2020

Description

Is it possible for there to be a way to set a task specific onError callback function? Right now, an onError function can be set but there's no way (afaik) to limit it to a single task like before() and after().

It would be nice if onError() can be used just like before() and after() callbacks.

Basically a post-execution callback that's only called if the execution of the event (not schedule) is unsucessful.

Example

In addition to this:

use Crunz\Schedule;

$schedule = new Schedule();

$task = $schedule->run('command/to/run');
$task->everyFiveMinutes();

$schedule
->onError(function() {
   // Send mail
})
->onError(function() {
   // Do something else
});

return $schedule;

It would be nice if this was supported :

use Crunz\Schedule;

$schedule = new Schedule();

$task = $schedule->run('command/to/run');
$task->everyFiveMinutes();

$task->onError(function() {
   // Send mail
})
->onError(function() {
   // Do something else
});

return $schedule;

@PabloKowalczyk
Copy link
Collaborator

Hello, actually it is possible internally to do this. I've implemented it as a part of #261. IMO it should be easy to make Event::addErrorCallback public, it just need some unit tests.
Would you like to provide a PR?

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

No branches or pull requests

2 participants