Chained Jobs Shared Data is a package that helps you share some data (usually an array) between chained jobs.
Chained Jobs Shared Data is a package that helps you share some data (usually an array) between chained jobs.
Renoki Co. on GitHub aims on bringing a lot of open source projects and helpful projects to the world. Developing and maintaining projects everyday is a harsh work and tho, we love it.
If you are using your application in your day-to-day job, on presentation demos, hobby projects or even school projects, spread some kind words about our work or sponsor our work. Kind words will touch our chakras and vibe, while the sponsorships will keep the open source projects alive.
You can install the package via composer:
composer require renoki-co/laravel-chained-jobs-shared-data
You just have to replace the default job’s Dispatchable
and Queueable
traits with the ones provided by this package.
// use Illuminate\Bus\Queueable;
// use Illuminate\Foundation\Bus\Dispatchable;
use RenokiCo\ChainedJobsSharedData\Traits\Dispatchable;
use RenokiCo\ChainedJobsSharedData\Traits\Queueable;
class MyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
// the rest of job here
}
The main use case is to share some data between chained jobs, while being able to modify it and be retrieved in the next jobs with the previous modifications.
CreateUser::withChain([
new CreateApiKey,
new MakeTestApiCall,
])->dispatch();
The CreateApiKey
and MakeTestApiCall
are the jobs that depend by the CreateUser
at glance.
Without using this package’s traits, the only workaround would be to trigger the CreateApiKey
in the CreateUser
job, then trigger the next one, and the next one, etc. and you will end up bad code to manage and troubleshoot.
If all job classes use the previous mentioned traits, having some shared data is going to ease the job:
// CreateUser.php
public function handle()
{
$user = $this->createUser();
$this->sharedData['user'] = $user;
}
// CreateApiKey.php
public function handle()
{
$apiKey = $this->createApiKeyForUser($this->sharedData['user']);
$this->sharedData['api_key'] = $apiKey;
}
// MakeTestApiCall.php
public function handle()
{
$this->makeApiCall(
$this->sharedData['user'],
$this->sharedData['api_key'],
);
}
vendor/bin/phpunit
Please see CONTRIBUTING for details.
If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.