Appearance
Job
Jobs should follow these characteristics:
- Reentrancy. If interrupted, a job can be restarted and completed successfully.
- Idempotence. A job can be called multiple times without changing the side effects.
- Concurrence. More than one instance of a job can run simultaneously (or use
ShouldBeUnique). - Sequence Independence. The order of the jobs doesn't matter (or use
Bus::chain()).
You can find more details on awesome talk: Matt Stauffer - Patterns That Pay Off
Dispatching
You SHOULD use dispatch() helper instead of Facade or DI, as they have different functionality (e.g., only dispatch() respects ShouldBeUnique interface). and you may face some limitations or even bugs. See details.
php
// GOOD
dispatch(new YouJob($argument));
// BAD
YouJob::dispatch($argument); // \Illuminate\Foundation\Bus\Dispatchable trait
// BAD
use Illuminate\Support\Facades\Bus;
Bus::dispatch(new YouJob($argument));