在Laravel Schedule

时间:2016-01-01 10:46:48

标签: php laravel laravel-5 laravel-5.1 job-scheduling

$schedule->call(function () 
        {
            error_log("Line Schedule 1:Start");
            //Send Email
            error_log("Line Schedule 1:End");

        })->everyFiveMinutes()->name('event_name:1')->withoutOverlapping();


        $schedule->call(function () 
        {
          error_log("Line Schedule 2:Start");
           //Send Email
          error_log("Line Schedule 2:End");
        })->everyFiveMinutes()->name('event_name:2')->withoutOverlapping();
        $schedule->call(function () 
        {
          error_log("Line Schedule 3:Start");
              //Send Email
          error_log("Line Schedule 3:End");
        })->everyFiveMinutes()->name('event_name:3')->withoutOverlapping();

我使用命令php artisan schedule运行这些schulders:运行并且我并行运行许多实例。我的日志文件说schulder 2第二次启动,即使它之前的实例还没有完成它。

[01-Jan-2016 11:30:08 UTC] Line Schedule 1:Start
[01-Jan-2016 11:30:11 UTC] Line Schedule 2:Start
[01-Jan-2016 11:30:13 UTC] Line Schedule 3:Start
[01-Jan-2016 11:30:15 UTC] Line Schedule 1:End
[01-Jan-2016 11:30:15 UTC] Line Schedule 2:Start
[01-Jan-2016 11:30:17 UTC] Line Schedule 2:End
[01-Jan-2016 11:30:17 UTC] Line Schedule 3:Start
[01-Jan-2016 11:30:19 UTC] Line Schedule 3:End
[01-Jan-2016 11:30:21 UTC] Line Schedule 2:End
[01-Jan-2016 11:30:21 UTC] Line Schedule 3:Start
[01-Jan-2016 11:30:22 UTC] Line Schedule 3:End
[01-Jan-2016 11:30:25 UTC] Line Schedule 3:End

1 个答案:

答案 0 :(得分:6)

只需调用 name()命名您的任务,并链接定义您的任务运行时间的方法。

$schedule->call(function () {
  //Some Code
})->everyFiveMinutes()
->name('some_name')
->withoutOverlapping();

对于匿名函数,需要名称以防止重叠