duandun3178 2014-10-26 16: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 11: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部