mateusjunges / trackable-jobs-for-laravel

This package allows you to easily track your laravel jobs!
https://junges.dev/documentation/trackable-jobs-for-laravel
MIT License
279 stars 17 forks source link

Idea: Base Class instead of Concern #49

Open Sairahcaz opened 7 months ago

Sairahcaz commented 7 months ago

Hi Mateus, thanks for this cool package!

An idea I had, was to change the Concern to a Base Class. This would make the API look much more natural imho:

<?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 App\Models\Podcast;
use Junges\TrackableJobs\Models\TrackedJob;
use Junges\TrackableJobs\TrackableJob;

class ProcessPodcastJob extends TrackableJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(Podcast $podcast)
    {
         parent::__construct($podcast);

         // Add your code here.
    }

    public function handle()
    {
        //
    }
}

VS:

<?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 Junges\TrackableJobs\Concerns\Trackable;
use App\Models\Podcast;
use Junges\TrackableJobs\Models\TrackedJob;

class ProcessPodcastJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Trackable {
        __construct as __baseConstruct;
    }

    public function __construct(Podcast $podcast)
    {
         $this->__baseConstruct($podcast);

         // Add your code here.
    }

    public function handle()
    {
        //
    }
}

What do you think?

mateusjunges commented 6 months ago

Hey 👋 this is actually one of the things I'm considering for v2. I'm not sure if I'll go with this yet, but I have to agree that the first one looks way better than using a trait.