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

[7.x] Add Callbacks with Output to Console Schedule #32633

Merged

Conversation

DougSisk
Copy link
Contributor

@DougSisk DougSisk commented May 1, 2020

Our health check provider allows POSTing output logs. Currently there's no built in way to do this. Instead of trying to figure out a one-size-fits-all to POST, my proposal is to use callbacks. This way you can use any kind of HTTP library you want, attach additional data, filter the output, etc.

I took the $onlyIfOutputExists argument from the emailOutputTo() command, so you can optionally only run the callback if an output was generated.

There are 4 callable methods, similar to the ping URL methods:

  • thenWithOutput()
  • thenIfWithOutput()
  • onSuccessWithOutput()
  • onFailureWithOutput()

Example:

$schedule->command('inspire')
    ->onSuccessWithOutput(function ($text) {
        Http::send('POST', 'https://healthcheckservice.test/abc123', [
            'body' => $text,
        ]);
    })
    ->daily();

@DougSisk DougSisk requested a review from GrahamCampbell May 1, 2020 19:42
@taylorotwell taylorotwell merged commit 28d28c4 into laravel:7.x May 3, 2020
@taylorotwell
Copy link
Member

taylorotwell commented May 3, 2020

I made a few tweaks to this. The "output" is injected into the Closure using the container->call() method like the other callbacks. This means you must name the variable $output.

Which leads me to my next point, I think these methods shouldn't really be called directly and in 8.x I'm going to make the standard then callbacks reflect into the Closure and inject a Stringable $output if the Closure is requesting it.

@taylorotwell
Copy link
Member

OK, got it fixed up on 8.x (master branch)... works with after, then, onSuccess, onFailure:

image

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.

3 participants