laravel 5 Schedule适用于-> cron('* */1 * * *'),但不适用于-> hourly() [英] laravel 5 schedule works with ->cron('* */1 * * *') but doesn't work with ->hourly()

查看:265
本文介绍了laravel 5 Schedule适用于-> cron('* */1 * * *'),但不适用于-> hourly()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个命令控制程序,这是我的代码

I create a command conttroller, this is my code

<?php namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Http\Controllers\AppController;


class UpdData extends Command {

    protected $name = 'upd:data';

    protected $description = 'Update data';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the command.
     *
     * @return void
     */
    public function handle()
    {
        $app = new AppController;
        $this->info("updated!");
        $app->update_data();
    }
}

这是我的crontab

This is my crontab

#!/bin/bash
PATH=/usr/bin
* * * * * php /home/ubuntu/workspace/app/artisan schedule:run 1>> /dev/null 2>&1

我的Kernel.php文件

<?php namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel {

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        'App\Console\Commands\Inspire',
        'App\Console\Commands\UpdData',
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('upd:data')->hourly(); // case 1
        $schedule->command('upd:data')->cron('* */1 * * *'); // case 2
    }
}

在案例1中,我尝试php artisan schedule:run,我收到No scheduled commands are ready to run.消息.在第2种情况下,它可以工作,但我需要自己指挥. 但这两种情况不会自动运行.我在cloud9上构建了平台,谢谢您!

On the case 1, I try to php artisan schedule:run, I get No scheduled commands are ready to run. message. On the case 2 it work, but I need to command by myself. But the two case doesn't not auto run it. I build my platform on the cloud9, I need your help thanks!

推荐答案

我没有找到原因,但是这段代码对我有用,如果我找到了真正的原因,我将更新我的答案.

I don't find the reason, but this code is work for me, if I find the real reason, I will update my answer.

这对我来说很有效,将hourly替换为cron.

This is work for me, replace hourly with cron.

protected function schedule(Schedule $schedule)
{
    $schedule->command('upd:data')->cron('0 * * * *');
}

这篇关于laravel 5 Schedule适用于-&gt; cron('* */1 * * *'),但不适用于-&gt; hourly()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆