Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

php - laravel cannot run scheduled command, while queue:listen run schedule() periodically

Note: My question has nothing to do with Command schedule in Laravel which schedule not work. But in my question the scheduling works, but it cannot call the artisan command.

I use laravel scheduling artisan command. I run the command directly from the console like this sudo -u www-data /var/www/market/artisan command:printer-serving 281H28.

I know it works because, I've Log::info('Working') at the entry of the handle() function of the command.

While when I use laravel's scheduling. And the cron works well, for below Log::info('command:printer-serving 281H28'); output the content to the console continuously.

But the artisan command not executed, it output nothing to the console, and not write something to the DB

In the Kernel.php

<?php namespace AppConsole;

use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel as ConsoleKernel;
use Log;

class Kernel extends ConsoleKernel {

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        'AppConsoleCommandsInspire',
        'AppConsoleCommandsCommandPrinterServing',
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  IlluminateConsoleSchedulingSchedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('inspire')->hourly();
        Log::info('command:printer-serving 281H28');
        $schedule->command('command:printer-serving --force 281H28')->everyMinute();
        //$schedule->command('printer-serving')->everyMinute();
        //$schedule->command(CommandPrinterServing::class, ['281H28'])->everyMinute();
    }

}

Command name, protected $signature = 'command:printer-serving {pid}';

Note No matter what string even not a command I put in $schedule->command() function, nothing will changes and not a error reported from the cron log or laravel log.

I want to know how to debug the $schedule->command() function.


Cron file vi /etc/cron.minutely/printer-task-minute

#!/bin/sh
cd /var/www/market
sudo -u www-data ./artisan command:regen-htaccess
#sudo -u www-data ./artisan schedule:run >> /dev/null 2>&1
sudo -u www-data ./artisan schedule:run

The weired thing is log output four thmes every 3 seconds.

> [2017-11-29 16:52:14] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:14] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:14] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:14] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:17] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:17] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:17] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:17] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:21] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:21] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:21] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:21] worker_env.INFO: command:printer-serving 281H28 
> [2017-11-29 16:52:24] worker_env.INFO: command:printer-serving 281H28

I'm puzzled about the log frequency, so I stop cron and beanstalkd. But the log output doesn't stop. Even I stop apache2, the log keeping output. Then I check the php process, and find there are four queue:listen --queue=xxxx --env=worker_env --delay=3 in the output of command ps aux | grep php. Here I found why the log output in that frequency, but I don't know why queue:listen execute the schedule() function as this question Understanding Queues and Scheduler on Laravel 5.2.


Each time I executed a artisan command sudo -u www-data /var/www/market/artisan xxxxx the schedule() function will be called one time. And if the command is queue:listen like sudo -u www-data /var/www/market/artisan queue:listen xxxxx the schedule() function will be called periodically. But the command in the schedule() will not run, except the Log::info(). Only when run schedule:run command, both the artisan command and Log::info() in schedule() will executed.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you should be using the below command

$schedule->command('printer_serving')->everyMinute()??;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...