imTigger / laravel-job-status

Add ability to track Job progress, status and result dispatched to Queue.
MIT License
407 stars 60 forks source link

Make LaravelJobStatusServiceProvider->updateJobStatus protected #39

Closed Shkryob closed 4 years ago

Shkryob commented 5 years ago

I would like to extend LaravelJobStatusServiceProvider because I want to handle errors differently but updateJobStatus method is private and I have to copy whole class instead of redefine single method. Can we make it protected?

crashkonijn commented 5 years ago

I'm currently working on somewhat of a rewrite, I might be able to help you out.

What would you like to change about the behavior?

Shkryob commented 5 years ago

I'm currently working on somewhat of a rewrite, I might be able to help you out.

What would you like to change about the behavior?

I want to ignore "Failed to get jobStatusId" exceptions because I don't always want to track jobs.

crashkonijn commented 5 years ago

I think something like this should work for you:

trait App\Traits\Trackable
{
    use Imtigger\LaravelJobStatus\Trackable {
        getJobStatusId as traitGetJobStatusId;
    };

    public function getJobStatusId()
    {
        return $this->statusId;
    }
}

So if I understand you correctly you have a single job class that you only want to track in certain instances?

Shkryob commented 5 years ago

@crashkonijn Yes, your code works but it will send extra DB requests trying to update job_status with ID = null.

crashkonijn commented 5 years ago

Perhaps something like this?

class TrackableJob extends NonTrackableJob
{
    use Trackable;

    public function __construct()
    {
        $this->prepareStatus();
    }
}

class NonTrackableJob
{
    public function handle()
    {
        // do your thing
    }
}

I will think about a better option to disable tracking