laravel-jobs
用于异步处理的后台作业和事件监听器。在使用队列作业、后台处理、事件,或者用户提到作业、队列、监听器、事件、异步处理时使用。
📖 中文导读:用于异步处理的后台作业和事件监听器。在使用队列作业、后台处理、事件,或者用户提到作业、队列、监听器、事件、异步处理时使用。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: laravel-jobs description: Background jobs and event listeners for async processing. Use when working with queued jobs, background processing, events, or when user mentions jobs, queues, listeners, events, async processing.
Laravel Jobs
Background jobs and event listeners: thin delegation layers to actions.
Core Concept
jobs-listeners.md - Job patterns:
- Jobs as thin delegation layers
- Queue configuration
- Retry logic and timeouts
- Unique jobs
- Job middleware
- Event listeners
- When to use jobs vs sync actions
Pattern
final class ProcessOrderJob implements ShouldQueue
{
use Dispatchable, Queueable;
public function __construct(
public readonly int $orderId,
) {}
public function handle(ProcessOrderAction $action): void
{
$order = Order::findOrFail($this->orderId);
$action($order);
}
public function middleware(): array
{
return [new WithoutOverlapping($this->orderId)];
}
}
// Listener
final class SendOrderConfirmationListener
{
public function handle(OrderPlaced $event): void
{
SendOrderConfirmationJob::dispatch($event->order->id);
}
}
Jobs delegate to actions. Keep domain logic in actions, not jobs.