DevOps

/laravel-agent:job:make

Create queued job, event, listener, or notification

Overview

The /job:make command generates queue components including queued jobs, events with broadcasting, event listeners, and multi-channel notifications. It leverages Laravel's queue system to handle background processing, event-driven architecture, and asynchronous notifications.

Usage

/laravel-agent:job:make [Name] [type]

Examples

# Create a queued job
/laravel-agent:job:make ProcessOrder

# Create an event with broadcasting
/laravel-agent:job:make OrderCreated event

# Create an event listener
/laravel-agent:job:make SendOrderEmail listener

# Create a multi-channel notification
/laravel-agent:job:make OrderShipped notification

Component Types

The command supports multiple queue component types:

Type Description Use Case
job Queued job (default) Background processing, long-running tasks
event Event with optional broadcasting Event-driven architecture, real-time updates
listener Event listener Responding to events, triggering actions
notification Multi-channel notification Email, SMS, Slack, database notifications
all Event + Listener + Notification combo Complete event-notification workflow

Available Features

Queue components can be enhanced with additional features:

  • batches - Batch multiple jobs together with progress tracking
  • chains - Chain jobs in sequence with failure handling
  • broadcasting - Broadcast events to WebSocket channels
  • retries - Automatic retry logic with exponential backoff

Generated Job Example

<?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;

class ProcessOrder implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct(
        public Order $order
    ) {}

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        // Process the order
        $this->order->process();
    }

    /**
     * Handle a job failure.
     */
    public function failed(\Throwable $exception): void
    {
        // Handle failure
    }
}

Generated Event Example

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class OrderCreated implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     */
    public function __construct(
        public Order $order
    ) {}

    /**
     * Get the channels the event should broadcast on.
     */
    public function broadcastOn(): array
    {
        return [
            new Channel('orders'),
        ];
    }
}

Generated Listener Example

<?php

namespace App\Listeners;

use App\Events\OrderCreated;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class SendOrderEmail implements ShouldQueue
{
    use InteractsWithQueue;

    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(OrderCreated $event): void
    {
        // Send order confirmation email
    }
}

Generated Notification Example

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class OrderShipped extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     */
    public function __construct(
        public Order $order
    ) {}

    /**
     * Get the notification's delivery channels.
     */
    public function via(object $notifiable): array
    {
        return ['mail', 'database'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->line('Your order has been shipped!')
            ->action('Track Order', url('/orders/'.$this->order->id))
            ->line('Thank you for your purchase!');
    }

    /**
     * Get the array representation of the notification.
     */
    public function toArray(object $notifiable): array
    {
        return [
            'order_id' => $this->order->id,
            'tracking_number' => $this->order->tracking_number,
        ];
    }
}

Best Practices

  1. Use queued jobs for time-consuming tasks - Keep web requests fast by offloading heavy work
  2. Implement proper error handling - Use failed() method and configure retry strategies
  3. Batch related jobs - Use job batching for better progress tracking and failure handling
  4. Use events for decoupled architecture - Events allow multiple listeners without tight coupling
  5. Queue notifications - Always queue notifications to avoid slowing down the request cycle

Related Agent

This command uses the laravel-queue agent.

See Also