laravel task scheduler

Background:
In business practice, it is often the way to use asynchronous tasks related to processing (time-consuming) tasks, then you may need to take the form of regular tasks to carry out. crontab linux comes with a timer can be a good tool to solve this problem.
Every item on the line when, if new asynchronous tasks must be performed on the script crontab configuration changes ××× Administrator. Because the need to move the server configuration, communication and coordination confirmation process is unavoidable.
laravel own schedule task scheduling can be a good solution to this pain point.

laravel task scheduling

php artisan schedule:run

Implementation steps

1, crontab -e increase the timing task scheduling performed laravel

#每分钟执行一次laravel任务调度,注意项目的绝对路径必须写正确。
* * * * * * php /site-path/artisan schedule:run >> /dev/null 2>&1 

Manually run scheduled tests:

php artisan schedule:run 

2, increasing the artisan Command command line script file

Not specific description, please refer to the official documentation

3, registered in the new Console kernel command line script file information

console kernel file /app/Console/Kernel.php
protected $commands = [
        "App\\Console\\Commands\\MigrateCompanyDataCommand",//迁移代记账公司数据到对象表
        "App\\Console\\Commands\\ReportCustomerSettleAccountEventCommand",//上报帐套结帐事件
        "App\\Console\\Commands\\IndicatorComputeCommand",//指标计算

    ];

4, the scheduling information configuration

Command-related increase in the scheduling configuration task execution frequency to complete deployment scheduled task.

protected function schedule(Schedule $schedule)
    {
         $schedule->command('command任务文件signature')->hourly();
    }

5, on the implementation of frequency

参照:Illuminate\Console\Scheduling\ManagesFrequencies

Common scheduling options
  • -> the cron ( ' *'); in the task scheduled to run custom Cron

  • -> everyMinute (); run once per minute task

  • -> everyFiveMinutes (); run every five minutes task

  • -> everyTenMinutes (); run the task once every ten minutes

  • -> everyThirtyMinutes (); run every thirty minutes a mission

  • -> hourly (); runs every hour task

  • -> daily (); run the task every day at midnight

  • -> dailyAt ('13: 00 '); 13:00 run a task daily

  • -> twiceDaily (1, 13); 1:00 & 1:00 p.m. daily tasks running

  • -> weekly (); run once a week tasks

  • -> monthly (); run once a month mission

  • -> monthlyOn (4, '15: 00 '); 15:00 4 month run a task

  • -> quarterly (); run once each quarter

  • -> yearly (); run once a year

  • -> timezone ( 'America / New_York'); zone setting

  • -> weekdays (); run only on weekdays task

  • -> sundays (); run the task every Sunday

  • -> mondays (); run the task every Monday

  • -> tuesdays (); run the task every Tuesday

  • -> wednesdays (); run the task every Wednesday

  • -> thursdays (); run the task every Thursday

  • -> fridays (); run the task every Friday

  • -> saturdays (); Every Saturday running task

  • -> between ($ start, $ end); running the task based on a specific time period

  • -> when (Closure); specific tasks based on test run

Guess you like

Origin blog.51cto.com/phpme/2400997