I
I
IgorVader2022-04-13 07:23:27
Task Schedulers
IgorVader, 2022-04-13 07:23:27

Schedule not working in Docker?

laravel running in docker
Previously everything worked when starting the container the following script is run

if [ "$APP_ROLE" = "app" ]; then
  echo "App role"
  #php /var/www/artisan migrate
elif [ "$APP_ROLE" = "cron" ]; then
  echo "Cron role"
  while [ true ]
  do
    #php /var/www/artisan schedule:run --verbose --no-interaction &
    php artisan job:dispatch ProcessParser
    php artisan job:dispatch ProcessParser &
    sleep 10
    php artisan job:dispatch checkTestimony
    php artisan job:dispatch checkTestimony &
    sleep 10
    php artisan job:dispatch SenderSms
    php artisan job:dispatch SenderSms &
    sleep 60
  done
else
    echo "Could not match the container role \"$APP_ROLE\""
    exit 1
fi

but it turned out that the queue is not created

when you run schedule:run from the container, the script runs for a couple of seconds
when the schedule:list command is empty, the list is empty

Kernel.php
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Jobs\ProcessParser;
use App\Jobs\checkTestimony;
use App\Jobs\SenderSms;
use App\Jobs\ClearingOldReadings;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule)
    {
        echo "run schedule";
        Log::info("run schedule");
        $schedule->job(new ClearingOldReadings)->daily();
        $schedule->job(new ProcessParser)->everyTwoMinutes();
        $schedule->job(new checkTestimony)->everyTwoMinutes();
        $schedule->job(new SenderSms)->everyMinute();
    }

    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

Added echo "run schedule"; when running schedule from a container, displays the message "run schedule"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question