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

Feedback feature #1306

Closed
wants to merge 8 commits into from
Closed

Feedback feature #1306

wants to merge 8 commits into from

Conversation

allanmcarvalho
Copy link

@allanmcarvalho allanmcarvalho commented Aug 24, 2023

This pull request add to Laravel Horizon the possibility of sending feedback regarding the execution of the job. This allows you to provide context to better understand what happened in that job.

You only need put the WithFeedback trait inside the Job and use the methods.

Eg.:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Laravel\Horizon\WithFeedbacks;

class CarWasherJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, WithFeedbacks;

    /**
     * Create a new job instance.
     */
    public function __construct(
        protected Car $car
    )
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        $this->afterFeedback('On success feedback', 'On failure feedback');

        $this->feedback(sprintf('CarWasherJob is running in car %s.', $this->car->id));

        $price = getPrice();

        $this->feedbackIf($price > 100, sprintf('The price appears to be too high: %s.', $price));

        $result = $this->car->wash();

        $this->feedback($result);

        $this->feedback(now());
    }
}

on dashboard

Captura de Tela 2023-08-24 às 17 52 24

Captura de Tela 2023-08-24 às 17 53 48

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

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