render-examples / php-laravel-docker

Larvel 5.8 PHP Docker Deployment on Render
https://render.com
MIT License
79 stars 683 forks source link

Example of triggering jobs on cron schedule? #24

Open connor11528 opened 2 years ago

connor11528 commented 2 years ago

Hi there, we have a schedule set to run a job on a regular basis but it doesn't seem this job is running. We've added this to the schedule function within app/Console/Kernel.php as outlined in the Laravel task scheduling docs.

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function() {
            (new JobListingsSeeder)->run();
        })->weekly()->sundays()->at('18:00');
        Artisan::call('cache:clear');

        $schedule->command('populateCompanyRaiseRounds')->twiceDaily(1, 13);
    }

However it doesn't appear that these commands are running. I see that there are Render docs on cron jobs. I was wondering, how can we run Artisan commands on a schedule while hosted on Render?

connor11528 commented 2 years ago

I think in order to accomplish this we'll need Supervisor to continually boot up the queue:work and schedule:run commands. Doing that requires edits to the Dockerfile..

Docs: https://laravel.com/docs/9.x/queues#supervisor-configuration Example with Apache: https://www.chrisgeiger.dev/posts/Running-Laravel-in-Docker-with-supervisord/ Example with Nginx: https://learn2torials.com/a/laravel8-production-docker-image