Laravel 5 - 没有重置的任务时间表不起作用

时间:2015-06-26 03:07:32

标签: laravel laravel-5 laravel-5.1

我尝试在Laravel 5上运行计划。当我运行它时,它的工作正常:

$schedule->call(function() {
   // do something here..
})->everyMinute();

但是当我添加withoutOverlapping()时,调度程序从不运行任务:

$schedule->call(function () {
   // do something here..
})->everyMinute()->name('job_name')->withoutOverlapping();

*这些计划代码写在/app/Console/Kernel.php

4 个答案:

答案 0 :(得分:4)

使用->everyMinute()时删除->withoutOverlapping()它仍会每分钟运行但不会重叠。

更新

自Laravel v.5.5 +以来,您可以指定在“不重叠”锁定到期之前必须经过多少分钟。

例如。 <10}分钟后,->withoutOverlapping(10)可用于解锁“重叠”。

答案 1 :(得分:4)

顺序很重要,但从未提及。

尝试一下

$schedule->call(function () {
   // do something here..
})->name('job_name')->withoutOverlapping()->everyMinute();

这对我有用:

  

(1)呼叫->(2)名称->(3)不重叠->(4)每天在->(5)onOneServer

弄乱订单时会出现类似错误

  

需要预定的事件名称以防止重叠。在'withoutOverlapping'之前使用name方法。

  

调用未定义的方法Illuminate \ Console \ Scheduling \ Schedule :: name()

答案 2 :(得分:1)

The cron withoutOverlapping() is now working. Let's understand how it works

For E.g:
$schedule->command('command')
                    ->hourly()
                    ->withoutOverlapping();
The withoutOverlapping means when cron runs then it will generate a lock file in storage/framework/ directory and once it's completed then it will delete the lock file. Now next time onwards, it will check weather the lock file is there or not. If lock file is there that means the previous cron is not completed and it will not allow the cron to overlap the previous one. 

In this scenario, the lock file is there into the storage/framework/ directory so that the cron is not working

**Lock file looks like:** schedule-random_string
For E.g: schedule-0bfdb7f0bc14b27d84c7d6f2a2528e85b0847fc6

**To Fix:** Remove or rename the lock file (storage/framework/schedule-0bfdb7f0bc14b27d84c7d6f2a2528e85b0847fc6)

答案 3 :(得分:0)

withoutOverlapping方法在执行命令时创建一个互斥文件,并在执行完成后删除该互斥文件。

计划程序检查是否存在任何不允许再次执行该命令的互斥文件。

在您的情况下,互斥文件不会被删除,这会阻止命令再次运行。

您可以使用php artisan cache:clear清除laravel缓存以使其再次正常工作