Scheduling

Use the scheduler for work that should start on a calendar schedule. The scheduler decides when work is due. A queue worker processes the job after it has been dispatched.

Schedule the picking-list job

Use the registered WritePickingList job. Add a task to the application's schedule() hook. This example schedules a picking list for order 84 at 06:15 each day in Sarajevo.

app/Application.php (excerpt)
use App\Jobs\WritePickingList;
use Atom\Scheduler\Schedule;

protected function schedule(Schedule $schedule): void
{
    $schedule->job(new WritePickingList(84, ["NOTEBOOK" => 2]), queue: "warehouse")
        ->daily()
        ->at("06:15")
        ->timezone("Europe/Sarajevo")
        ->name("Write picking list for order 84");
}

Each due occurrence dispatches the job with the same arguments. Use this pattern when those arguments are known at registration. For work that needs to find a fresh set of orders each time, schedule a job whose handler loads the current orders.

Scheduler and worker

Process What it does
php atom schedule:run Checks which tasks are due in the current minute and dispatches the picking-list job to warehouse.
php atom queue:work --queue=warehouse Picks up queued jobs and invokes their handlers. WritePickingList::handle() writes the file.

With the file or database queue driver, the scheduler can finish as soon as the job is queued. The worker runs separately and can process jobs that were dispatched outside the scheduler as well. With the default sync driver, dispatch runs the handler inside the scheduler process. See Queues and scheduling to select a driver.

Frequencies

Use fluent frequencies for common schedules or pass an explicit cron expression.

$task->everyFiveMinutes();
$task->daily()->at("06:15");
$task->cron("15 6 * * 1-5");

at() uses 24-hour HH:MM format. Tasks use UTC unless you set a timezone.

Running the Scheduler

Use php atom schedule:list to see configured tasks and their next run times. Configure your host to invoke schedule:run every minute. On a host that uses cron, the entry looks like this:

* * * * * cd /path/to/application && php atom schedule:run

For an asynchronous driver, run the queue worker separately under a process supervisor.