Scheduler : Large (longer) jobs, multiple tenants, stops. #491
BartMommens
started this conversation in
General
Replies: 2 comments 2 replies
-
IMHO, this is a wrong implementation. What should you do when your tenants will be 100/500/1000? Use only |
Beta Was this translation helpful? Give feedback.
1 reply
-
@masterix21 Going forward on your great advice i've refactored my code to the following: <?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('LAAS:Exports:daily-full')->dailyAt('00:00')->runInBackground();
$schedule->command('LAAS:Jobs:hourly')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
} and create new classes to handle the jobs: <?php
namespace App\Console\Commands;
use App\Jobs\ExportAllCSVDataToGoogleDriveJob;
use Illuminate\Console\Command;
use Spatie\Multitenancy\Commands\Concerns\TenantAware;
use App\Models\Tenant\Tenant;
class DailyFullExportCommand extends Command
{
use TenantAware;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'LAAS:Exports:daily-full {--tenant=*}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command executes the daily full data export';
/**
* Execute the console command.
*/
public function handle(): void
{
dispatch(new ExportAllCSVDataToGoogleDriveJob());
}
} namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Tenant\Tenant;
use App\Jobs\CloseExpiredWorkSessionsJob;
use App\Jobs\ExportLmraOverviewCSVDataToGoogleDriveJob;
class HourlyJobsCommand extends Command
{
use TenantAware;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'LAAS:Jobs:hourly {--tenant=*}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Executes all jobs that need to run on an hourly basis';
/**
* Execute the console command.
*/
public function handle(): void
{
dispatch(new ExportLmraOverviewCSVDataToGoogleDriveJob());
dispatch(new CloseExpiredWorkSessionsJob());
}
} Any advice concerning this approach? I want to thank you for your time, and my apologies for posting this in the issues section earlier. Have a nice weeken. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm not 100% sure if it's a bug or just something i'm doing wrong.
I have an issue with a cronjob running the Laravel scheduler.
Info:
The Cronjob runs every minute like described in the laravel docs :
app/production/current && php artisan tenants:artisan schedule:run >> /tmp/export-job-prod.log 2>&1
This will trigger the run schedule of laravel and it will start executing the jobs:
Let's say it's now 2:00 and the cronjob is triggered:
When it starts it loops over all 7 tenants one by one and executes all 3 jobs per tenant.
The largest job is the
ExportAllCSVDataToGoogleDriveJob::class
and depending on the client it take up somewhere from 10 upto 40 seconds. The first 3 or 4 tenant jobs all are being executed , the 4th tenant is a rather big one and sometimes it takes upto 40seconds.So when it hits the 5th to 7th client, nothing gets executed anymore because by that time it is already 2:01 and it just doesn't execute the "hourly" jobs anymore.
Log below:
When it runs at other times and does not execute the large job per tenant the other two jobs are successfully executed due to the fact that it runs under a minute.
When i change all jobs to run
->everyMinute()
and only execute the cron job every hour everything works fine since it always hits the jobs and the "condition" every minute still stands.So i'm not sure it's a bug or i'm just using the wrong approach here. Is there a way to run the cron task every minute but use the laravel ->hourly() functionality without it stopping on tenants that get executed on hour:01?
Thanks in advance.
Best regards,
Bart M.
Beta Was this translation helpful? Give feedback.
All reactions