laravel-task-scheduling

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Task Scheduling

任务调度

Run scheduled tasks predictably across environments.
跨环境可预测地运行调度任务。

Commands

命令

// routes/console.php
<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schedule;

Schedule::command('reports:daily')
    ->dailyAt('01:00')
    ->withoutOverlapping()
    ->onOneServer()
    ->runInBackground()
    ->evenInMaintenanceMode();
// routes/console.php
<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schedule;

Schedule::command('reports:daily')
    ->dailyAt('01:00')
    ->withoutOverlapping()
    ->onOneServer()
    ->runInBackground()
    ->evenInMaintenanceMode();

Patterns

模式

  • Guard long-running commands with
    withoutOverlapping()
  • Use
    onOneServer()
    when running on multiple nodes
  • Emit logs/metrics for visibility; consider notifications on failure
  • Feature-flag risky jobs via config/env
  • 使用
    withoutOverlapping()
    保护长时间运行的命令
  • 在多节点运行时使用
    onOneServer()
  • 生成日志/指标以确保可见性;考虑在任务失败时发送通知
  • 通过配置/环境变量为高风险任务设置功能开关