我迷失了我的错误,我看不到其他人遇到这个问题,所以它一定是我。
我刚设置Indatus\Dispatcher\ServiceProvider
并且运行正常。出于测试目的,我只是每5分钟运行一个预定的事件来添加日志条目。
由于某种原因,它正在复制日志条目。
这是输出的样子:
[2014-10-26 19:00:15] local.INFO: This is a test [] []
[2014-10-26 19:00:15] local.INFO: This is a test [] []
[2014-10-26 19:05:12] local.INFO: This is a test [] []
[2014-10-26 19:05:13] local.INFO: This is a test [] []
[2014-10-26 19:10:09] local.INFO: This is a test [] []
[2014-10-26 19:10:10] local.INFO: This is a test [] []
以下是实际的预定fire()
事件:
public function fire()
{
Log::info('This is a test');
}
schedule()
:
public function schedule(Schedulable $scheduler)
{
return $scheduler->everyMinutes(5);
}
我检查了scheduled:summary
,它只显示一次:
+----------------+------------------+-----------+--------+------+--------------+-------+-------------+--------+
| Environment(s) | Name | Args/Opts | Minute | Hour | Day of Month | Month | Day of Week | Run as |
+----------------+------------------+-----------+--------+------+--------------+-------+-------------+--------+
| * | schedule:test | | */5 | * | * | * | * | |
+----------------+------------------+-----------+--------+------+--------------+-------+-------------+--------+
最后是我的crontab条目,它只列在文件中一次:
* * * * * php /vagrant/myapp/artisan scheduled:run 1>> /dev/null 2>&1
我看不到会导致它运行两次的任何重复。
我有什么想法我错了吗?
**编辑:**
根据要求,测试命令的全文:
使用Indatus \ Dispatcher \ Scheduling \ ScheduledCommand; 使用Indatus \ Dispatcher \ Scheduling \ Schedulable; 使用Indatus \ Dispatcher \ Drivers \ Cron \ Scheduler; 使用Symfony \ Component \ Console \ Input \ InputOption; 使用Symfony \ Component \ Console \ Input \ InputArgument;
class NewSchedule extends ScheduledCommand {
/**
* The console command name.
*
* @var string
*/
protected $name = 'schedule:test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This is a test command';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* When a command should run
*
* @param Scheduler $scheduler
* @return \Indatus\Dispatcher\Scheduling\Schedulable
*/
public function schedule(Schedulable $scheduler)
{
return $scheduler->everyMinutes(5);
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
Log::info('This is a test');
}
}
答案 0 :(得分:4)
通过从root发出此命令,检查以确保只有一个cron守护程序正在运行:
ps aux | grep [c]ron
...并确保只有一个结果。如果还有更多,则运行多个进程并触发Dispatcher。
您还可以确保没有为多个用户(vagrant
和root
错误地添加Dispatcher crontab,例如:
sudo ls /var/spool/cron/crontabs
...查看哪些用户有效crontabs
。应该只有一个结果。