Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 2.33 KB

File metadata and controls

72 lines (51 loc) · 2.33 KB
title Task Scheduling
description Fluently and expressively define your application's command schedule

Task Scheduling

Introduction

Laravel Zero ships with Laravel's task scheduler, which offers a fresh approach to managing scheduled tasks on your server. The scheduler allows you to fluently and expressively define your command schedule within your application itself, so only a single cron entry is needed on your server.

Defining Schedules

Every Laravel Zero command may define its own schedule using the schedule method. This keeps the schedule right next to the logic it runs:

use Illuminate\Console\Scheduling\Schedule;

/**
 * Define the command's schedule.
 */
public function schedule(Schedule $schedule): void
{
    $schedule->command(static::class)->everyMinute();
}

A variety of schedule frequencies may be assigned to your task:

$schedule->command(static::class)->hourly();

$schedule->command(static::class)->dailyAt('13:00');

$schedule->command(static::class)->weekdays()->hourly();

You are also free to schedule closures or operating system commands, and to apply any of the scheduler's other options — such as preventing overlaps or running tasks in the background:

$schedule->command(static::class)
    ->everyFiveMinutes()
    ->withoutOverlapping()
    ->runInBackground();

For a complete list of the available schedule frequencies and options, consult the task scheduling documentation on the Laravel website.

Running the Scheduler

The scheduler needs to be invoked every minute in order to evaluate your schedule. Add the following cron entry to the server that runs your application:

* * * * * php /path-to-your-project/movie-cli schedule:run >> /dev/null 2>&1

Viewing Scheduled Tasks

You may use the schedule:list Artisan command to view an overview of the tasks scheduled by your application and the next time each one is due to run:

php application schedule:list