Laravel没有运行工作

时间:2016-12-16 20:24:40

标签: php laravel-5.2 scheduled-tasks cron-task

我正在使用 laravel 5.2 ,我的工作设置如下:

<?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\FetchTweets::class,
        \App\Console\Commands\FetchTweetMentions::class,
        \App\Console\Commands\FetchTweetListsAddedToo::class,
        \App\Console\Commands\LogRotater::class,
        \App\Console\Commands\FetchReadMes::class,
        \App\Console\Commands\FetchEveMarketPrices::class,
        \App\Console\Commands\FetchEveRegions::class,
        \App\Console\Commands\FetchEveMarketGroupInformation::class,
        \App\Console\Commands\FetchEveMarketTypes::class,
        \App\Console\Commands\FetchEveOnlineRegionTypeHistoryInformation::class,
        \App\Console\Commands\CleanEveTables::class,
        \App\Console\Commands\PublishTweets::class,
        \App\Console\Commands\FetchTwitterBlocks::class,
        \App\Console\Commands\FetchTwitterFollowers::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // ...

        $schedule->command('log_rotater')
            ->everyThirtyMinutes()
            ->withoutOverlapping()
            ->appendOutputTo('storage/logs/log_rotation.log');
    }
}

我已经注释掉了其他工作,因为我觉得如果我修复了一个它会修复它们或者我将有办法解决它们。基本上这项工作永远不会运行。

自从。

我怎么知道这个?它假设旋转的日志文件大小增加到几个演出,当它们从未假设大于兆。我习惯每天都设置这个,但现在我把它改为每半个小时。

它仍然无法运行。

我可以通过执行php artisan log_rotator手动运行它并且没有错误,它运行,它旋转日志的生命是宏伟的。

但它似乎不想在计划时运行。

思想吗

您是否创建了实际的cronjob来运行调度程序?

# m h  dom mon dow   command
* * * * * php ~/personal_site/artisan schedule:run >> /dev/null 2>&1

该命令是否有效?

这是其中一个输出的示例:

xxx@ubuntu:~$ php ~/personal_site/artisan schedule:run
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c; '/usr/bin/php7.0' 'artisan' fetch_tweets; rm /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c) >> 'storage/logs/tweets.log' 2>&1 &

所以......是的,是的。

帮助

更新两个

以下内容应该告诉您需要知道的任何事情。

xxx@ubuntu:~$ php /home/xxx/personal_site/artisan schedule:run >> /home/xxx/personal_site/storage/cron.log 2>&1
xxx@ubuntu:~$ cd personal_site/storage/
xxx@ubuntu:~/personal_site/storage$ cat cron.log 
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c; '/usr/bin/php7.0' 'artisan' fetch_tweets; rm /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c) >> 'storage/logs/tweets.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-8f666afb45a162c3e7fcdd31c3b7334b7321f169; '/usr/bin/php7.0' 'artisan' fetch_twitter_blocks; rm /home/xxx/personal_site/storage/framework/schedule-8f666afb45a162c3e7fcdd31c3b7334b7321f169) >> 'storage/logs/tweet_block.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-00cca655481aaf25de2c659589a2eb94feaf5775; '/usr/bin/php7.0' 'artisan' fetch_twitter_followers; rm /home/xxx/personal_site/storage/framework/schedule-00cca655481aaf25de2c659589a2eb94feaf5775) >> 'storage/logs/twitter_followers.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-ee75cb261c4f273c31e1c7ce526ee8ad0b810907; '/usr/bin/php7.0' 'artisan' fetch_tweet_mentions; rm /home/xxx/personal_site/storage/framework/schedule-ee75cb261c4f273c31e1c7ce526ee8ad0b810907) >> 'storage/logs/tweet_mentions.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-3b5a4c06df2d042fff061daba42e20e7e4ff43fc; '/usr/bin/php7.0' 'artisan' fetch_tweet_lists_added_too; rm /home/xxx/personal_site/storage/framework/schedule-3b5a4c06df2d042fff061daba42e20e7e4ff43fc) >> 'storage/logs/tweet_list.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c; '/usr/bin/php7.0' 'artisan' fetch_tweets; rm /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c) >> 'storage/logs/tweets.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-8f666afb45a162c3e7fcdd31c3b7334b7321f169; '/usr/bin/php7.0' 'artisan' fetch_twitter_blocks; rm /home/xxx/personal_site/storage/framework/schedule-8f666afb45a162c3e7fcdd31c3b7334b7321f169) >> 'storage/logs/tweet_block.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-00cca655481aaf25de2c659589a2eb94feaf5775; '/usr/bin/php7.0' 'artisan' fetch_twitter_followers; rm /home/xxx/personal_site/storage/framework/schedule-00cca655481aaf25de2c659589a2eb94feaf5775) >> 'storage/logs/twitter_followers.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-ee75cb261c4f273c31e1c7ce526ee8ad0b810907; '/usr/bin/php7.0' 'artisan' fetch_tweet_mentions; rm /home/xxx/personal_site/storage/framework/schedule-ee75cb261c4f273c31e1c7ce526ee8ad0b810907) >> 'storage/logs/tweet_mentions.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-3b5a4c06df2d042fff061daba42e20e7e4ff43fc; '/usr/bin/php7.0' 'artisan' fetch_tweet_lists_added_too; rm /home/xxx/personal_site/storage/framework/schedule-3b5a4c06df2d042fff061daba42e20e7e4ff43fc) >> 'storage/logs/tweet_list.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-1357d5ceb1399278a39d91725089a0df39036ecc; '/usr/bin/php7.0' 'artisan' publish_tweets; rm /home/xxx/personal_site/storage/framework/schedule-1357d5ceb1399278a39d91725089a0df39036ecc) >> 'storage/logs/sent_tweets.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c; '/usr/bin/php7.0' 'artisan' fetch_tweets; rm /home/xxx/personal_site/storage/framework/schedule-1b9fbd28988b6ce27513da6dcf3d00eec059484c) >> 'storage/logs/tweets.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-8f666afb45a162c3e7fcdd31c3b7334b7321f169; '/usr/bin/php7.0' 'artisan' fetch_twitter_blocks; rm /home/xxx/personal_site/storage/framework/schedule-8f666afb45a162c3e7fcdd31c3b7334b7321f169) >> 'storage/logs/tweet_block.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-00cca655481aaf25de2c659589a2eb94feaf5775; '/usr/bin/php7.0' 'artisan' fetch_twitter_followers; rm /home/xxx/personal_site/storage/framework/schedule-00cca655481aaf25de2c659589a2eb94feaf5775) >> 'storage/logs/twitter_followers.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-ee75cb261c4f273c31e1c7ce526ee8ad0b810907; '/usr/bin/php7.0' 'artisan' fetch_tweet_mentions; rm /home/xxx/personal_site/storage/framework/schedule-ee75cb261c4f273c31e1c7ce526ee8ad0b810907) >> 'storage/logs/tweet_mentions.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-3b5a4c06df2d042fff061daba42e20e7e4ff43fc; '/usr/bin/php7.0' 'artisan' fetch_tweet_lists_added_too; rm /home/xxx/personal_site/storage/framework/schedule-3b5a4c06df2d042fff061daba42e20e7e4ff43fc) >> 'storage/logs/tweet_list.log' 2>&1 &
Running scheduled command: (touch /home/xxx/personal_site/storage/framework/schedule-1357d5ceb1399278a39d91725089a0df39036ecc; '/usr/bin/php7.0' 'artisan' publish_tweets; rm /home/xxx/personal_site/storage/framework/schedule-1357d5ceb1399278a39d91725089a0df39036ecc) >> 'storage/logs/sent_tweets.log' 2>&1 &

2 个答案:

答案 0 :(得分:1)

看看你的方法,我认为这是不正确的:

$schedule->command('log_rotater')
   .....

你在这里提到log_rotater;但是$signature\App\Console\Commands\LogRotater::class中的表现如何 它可能类似于log:rotate

command()的论点应该是工匠的命令;所以在$signature

\App\Console\Commands\LogRotater::class中定义

你提到你是调度程序运行;但它只运行'FetchTweets'任务;没别的。

答案 1 :(得分:0)

我认为@tkausl走在正确的轨道上:命令开头的“〜”可能并不指向您期望的根文件夹......

我首先删除stdout / stderr重定向,也可以通过在cron文件的顶部添加它来邮寄给自己:

MAILTO=me@company.com
MAILFROM=server@company.com

这应该允许您查看cron作业输出的任何错误消息...

我的猜测,正如我所说,你的cron作业是以不同的用户身份运行(可能是root用户?)而且“〜/ personal_site / artisan”在这种情况下不存在......

或者,您也可以尝试直接使用绝对路径,看看是否存在问题...

希望这有帮助!