PHP code example of mateusjunges / laravel-trackable-jobs
1. Go to this page and download the library: Download mateusjunges/laravel-trackable-jobs library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mateusjunges / laravel-trackable-jobs example snippets
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\TrackableJob;
class ProcessPodcastJob extends TrackableJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
//
}
}
dispatch(new ProcessPodcastJob($podcast));
return [
/*
| The table where the tracked jobs will be stored.
| By default, it's called 'tracked_jobs'.
*/
'tables' => [
'tracked_jobs' => 'tracked_jobs',
],
'using_uuid' => false,
];
Bus::dispatchChain([
new OptimizePodcast($podcast),
new CompressPodcast($podcast),
new ReleasePodcast($podcast)
])->dispatch();
public function trackableType(): ?string
{
return $this->podcast->getMorphClass();
}
public function trackableKey(): ?string
{
return (string) $this->podcast->id;
}
public function steps(): \Illuminate\Database\Eloquent\Relations\MorphMany
{
return $this->morphMany(Junges\TrackableJobs\Models\TrackedJob::class, 'trackable');
}
$steps = Podcast::find($id)->steps;
public function handle()
{
//Do your stuff here
return "Job finished successfully";
}
namespace App\Providers;
use App\Models\YourCustomModel;
use Illuminate\Support\ServiceProvider;
use Junges\TrackableJobs\Contracts\TrackableJobContract;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(TrackableJobContract::class, YourCustomModel::class);
}
}