duandun3178 2014-10-27 00:20
浏览 15
已采纳

Laravel重复输出的调度程序

I'm lost on what I'm doing wrong, and I can't see anyone else with this problem, so it's gotta be me.

I've just setup Indatus\Dispatcher\ServiceProvider and have everything running just fine. For testing purposes, I'm just running a single scheduled event every 5 minutes to add a log entry.

For some reason, it's duplicating the log entries.

Here's what the output is looking like:

[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 [] []

Here's the actual scheduled fire() event:

public function fire()
{
    Log::info('This is a test');
}

The schedule() :

public function schedule(Schedulable $scheduler)
{
    return $scheduler->everyMinutes(5);

}

and I've checked the scheduled:summary and it's only showing once:

+----------------+------------------+-----------+--------+------+--------------+-------+-------------+--------+
| Environment(s) | Name             | Args/Opts | Minute | Hour | Day of Month | Month | Day of Week | Run as |
+----------------+------------------+-----------+--------+------+--------------+-------+-------------+--------+
| *              | schedule:test    |           | */5    | *    | *            | *     | *           |        |
+----------------+------------------+-----------+--------+------+--------------+-------+-------------+--------+

And finally my crontab entry, which is only listed in the file once:

* * * * * php /vagrant/myapp/artisan scheduled:run 1>> /dev/null 2>&1

I can't see any duplication that would cause it to run twice.

Any ideas what I've got wrong?

**Edit: **

As requested, full text from the test command:

use Indatus\Dispatcher\Scheduling\ScheduledCommand; use Indatus\Dispatcher\Scheduling\Schedulable; use Indatus\Dispatcher\Drivers\Cron\Scheduler; use Symfony\Component\Console\Input\InputOption; use 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');
    }


}
  • 写回答

1条回答 默认 最新

  • douchui1657 2014-10-31 19:39
    关注

    Check to make sure that only one cron daemon is running, by issuing this command, from root:

    ps aux | grep [c]ron
    

    ...and make sure there is only one result. If there are more, then multiple processes are running and triggering Dispatcher.

    You can also make sure the Dispatcher crontab wasn't mistakenly added for multiple users (both vagrant and root, for example:

    sudo ls /var/spool/cron/crontabs
    

    ...to see what users have active crontabs. There should only be one result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器