我迷失了自己做错了什么,我看不到其他人有这个问题,所以一定是我。
我刚刚设置了IndatusDispatcherServiceProvider
,一切都运行得很好。出于测试目的,我只是每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\ScheduledCommand;使用Indatus\Dispatcher\Schedullable;使用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 IndatusDispatcherSchedulingSchedulable
*/
public function schedule(Schedulable $scheduler)
{
return $scheduler->everyMinutes(5);
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
Log::info('This is a test');
}
}
通过从root:发出此命令,检查以确保只有一个cron守护进程正在运行
ps aux | grep [c]ron
并确保只有一个结果。如果有更多,则多个进程正在运行并触发Dispatcher。
您还可以确保没有为多个用户错误地添加Dispatcher crontab(包括vagrant
和root
,例如:
sudo ls /var/spool/cron/crontabs
以查看哪些用户具有活动CCD_ 7。应该只有一个结果。