2
votes

I have problem to run artisan queue:work command using task scheduling in laravel 5.3

app/Console/Kernel.php code

<?php

namespace App\Console;

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

class Kernel extends ConsoleKernel {
    protected $commands = [];

    \Log::info('schedule:run');
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('queue:work --tries=3')
            ->everyMinute()
            ->withoutOverlapping()
            ->evenInMaintenanceMode()
            ->sendOutputTo(storage_path() . '/queue-logs/queue-jobs.log', true);
    }
}

I setup cron job in server:

* * * * * /usr/local/bin/php /home/s***app/public_html/artisan schedule:run

I got log in \Log::info('schedule:run'); in /queue-logs/queue-jobs.log file every minutes. But command queue:work --tries=3 not work and queue stored in job table not processed.

And also my hosting provider block my every minutes request and suggest me to run this cron to 15 min instead of 1 minute

1
I will suggest you to use a vendor for cron management in Laravel. It will make your job easy.Avishake
@Avishake how to use vendor for cron? I don't hear about it...kupendra
use github.com/liebig/cron. It is a great vendor. I am using. It is easy to use and maintain.Avishake
@Avishake i don't want to use any packages because laravel provides inbuilt task scheduling..kupendra
Yes I know. But while I am try to use that, that will make some problem. So I go for this package. This package make my problem easy and if there is any issue and you post in to there git, they reply it very quickly.Avishake

1 Answers

0
votes

I was experiencing the same issue in Laravel 5.7, using Ubuntu 16.04: My jobs in the job table were being queued but not being executed:

This is what I did:

Ssh to your server i.e. ssh username@ip

Then run sudo nano /etc/crontab

Add the following line inside the file * * * * * username php /var/www/your_laravel_project/artisan schedule:run >> /dev/null 2>&1

Make sure you do not forget this part here: /artisan after your project folder. I was doing this mistake and my cron was not running.

Explanation:

.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* * * * * user-name command-to-be-executed

Then run sudo systemctl restart cron to restart the cron service.

You can also check it's status using sudo systemctl status cron

Tip: It would be better if you do not use shared hosting to since many shared hosting services won't allow you to run crons every minute. Digital Ocean has droplet packages for as low as $20 per month. Consider setting up your own server using Digital Ocean, AWS etc.