Task scheduler works on homestead, but not on shared hosting

Published 6 months ago by patrikw1

Hi, i have following methods in Kernel class:

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

        //restarts queue worker, preventing memory stuck
        $schedule->command('queue:restart')
                 ->everyMinute()
                 ->name('restarts queue worker');

        //Each Video total_video_views will be accurately updated for example on daily basis.
        $schedule->command('video:update-views')
                 ->everyMinute()
                 ->between('9:00', '23:00')
                 ->name('updates all video views');


        //Page Insights will be updated
        $schedule->call(function () {
            $this->app->queue->push(new UpdatePageInsights);
        })
                 ->everyMinute()
                 ->name('page insights');




        //this is alternative to supervisor since shared hosting someties doesnt provide supervisor
        //so we use cron instead to keep queue worker up
        $schedule->command('queue:work --queue=high,default --memory=1024')
                 ->everyMinute()
                 ->name('keeps queue worker active')
                 ->withoutOverlapping();
    }

i run cron as: php web/artisan schedule:run

without & mark etc. When i set cron on the server and tell cron to mail me the output of the cron, i get excepted output with all those names i set on scheduled tasks..

However, none of these command get executed, i have no output in my lumen.log as i expected, and no new jobs in the database queue..

When i log on the server via SSH, and type php artisan schedule:run, it works, Lumen.log is filled with information and queue jobs are pushed to the default queue, and being processed.

Another strange thing is that, when i remove cron job from server, queue worker keeps processing jobs.. even though queue:work command is not executed by task scheduler anymore

Please can somebody explain me how is this possible?

Best Answer (As Selected By patrikw1)
patrikw1

This is fixed now, hosting provider informed me that my cron got stuck and therefore he had to kill it..

The second issue was that i have to use queue:listen now instead of queue:work, since queue worker doesn't execute handle() method in my job.

Dry7
Dry7
6 months ago (151,680 XP)

@patrikw1 may a typo in crontab? try sending an email to yourself in one of these commands

patrikw1

@Dry7 Thanks for reply, actually i was trying in each on of these commands to Log::error('insiside command') to see if a get anything i have done this:

In Kernel.php:

 /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        //Each Video total_video_views will be accurately updated for example on daily basis.
        $schedule->command('video:update-views')
                 ->everyMinute()
                 ->name('updates all video views');
    }

video:update-views signature/command - App\Console\Commands\UpdateAllVideoViews:

public function handle()
    {
    //Eloquent collection
        $videos = Video::get();

    \Log::error('inside command')

        Queue::later(Date::now()->addSeconds(10),  new UpdateVideoViews($videos));
        $this->info('All videos views will be updated shortly.');
    }

And see the App\Jobs\UpdateVideoViews job itseld:

/**
     * Execute the job that updates all videos total_video_views attribute
     *
     * @return void
     */
    public function handle(VideoFeedService $videoFeed)
    {

    \Log::error('inside job')
        $videoFeed->insights($this->videos)->addViews();
    }

The only log i can see in lumen.log is inside command, it never gets to Log the job, even though when job is visible in database, after defined delay it gets picked up by queue worker.

However this code is deployed later, maybe there is a queue:work daemon still running.. the question is.. how do i stop him? how do i force queue:work do recognize code changes? i dont have any deployment commands for this..

From reading i found that i could run php artisan down and it will just kill queue:work process, but i am on lumen and i dont have such possibility..

Is there any linux command or anything i can do to force queue:work to STOP?

patrikw1

This is fixed now, hosting provider informed me that my cron got stuck and therefore he had to kill it..

The second issue was that i have to use queue:listen now instead of queue:work, since queue worker doesn't execute handle() method in my job.

Please sign in or create an account to participate in this conversation.