aaronfrancis/enqueue

Declarative job enqueueing with schedule-aware dispatch for Laravel

Maintainers

Package info

github.com/aarondfrancis/enqueue

pkg:composer/aaronfrancis/enqueue

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

v0.1.0 2025-12-28 20:20 UTC

This package is auto-updated.

Last update: 2026-03-01 00:48:48 UTC


README

Latest Version on Packagist Tests Total Downloads PHP Version License

Declarative job enqueueing with schedule-aware dispatch for Laravel.

Jobs often need to dispatch themselves on a schedule—syncing data every hour, processing uploads every few minutes, sending reports on weekdays. Normally this means scattering scheduling logic across routes/console.php while the job sits elsewhere, or writing awkward wrapper commands.

Enqueue lets the job own its entire lifecycle. Each job declares how to enqueue itself (maybe one instance per warehouse, or one per pending upload) and optionally when (hourly, weekdays, or custom logic). Run jobs:enqueue every minute and each job takes care of the rest.

Installation

composer require aaronfrancis/enqueue

Usage

Implement the Enqueueable interface on any job:

<?php

namespace App\Jobs;

use AaronFrancis\Enqueue\Contracts\Enqueueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class SyncInventory implements ShouldQueue, Enqueueable
{
    use Queueable;

    public function __construct(public int $warehouseId) {}

    public function handle(): void
    {
        // Sync inventory for this warehouse...
    }

    public static function enqueue(): void
    {
        Warehouse::all()->each(function ($warehouse) {
            dispatch(new static($warehouse->id));
        });
    }
}

Schedule the command to run every minute:

// routes/console.php
Schedule::command('jobs:enqueue')->everyMinute();

Controlling When Jobs Enqueue

Add a shouldEnqueue() method to control timing:

use Illuminate\Console\Scheduling\CallbackEvent;

public static function shouldEnqueue(CallbackEvent $event): CallbackEvent
{
    return $event->hourly()->weekdays();
}

Or return a boolean for custom logic:

public static function shouldEnqueue(CallbackEvent $event): bool
{
    return Cache::get('sync_enabled', true);
}

Preview Mode

See what would be enqueued without dispatching:

php artisan jobs:enqueue --pretend

Requirements

  • PHP 8.2+
  • Laravel 10, 11, or 12.24+

License

MIT