Files
2026-04-28 21:14:25 +03:00

176 lines
7.7 KiB
PHP

<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
\App\Console\Commands\MigrateFromDate::class,
\App\Console\Commands\DocumentSyncFolders::class,
\App\Console\Commands\NotificationCheckAll::class,
\App\Console\Commands\NotificationCheckDeletedJoints::class,
\App\Console\Commands\NotificationCheckRepairLog::class,
\App\Console\Commands\NotificationCheckRepairRate::class,
\App\Console\Commands\NotificationCheckLineList::class,
\App\Console\Commands\NotificationCheckPDFDocuments::class,
\App\Console\Commands\NotificationCheckWeldlogCertificate::class,
\App\Console\Commands\NotificationCheckIncomingControlCertificate::class,
\App\Console\Commands\NotificationCheckNDEMatrixDiscrepancies::class,
\App\Console\Commands\NotificationCheckNDTCalculation::class,
\App\Console\Commands\NotificationCheckManageNDT::class,
\App\Console\Commands\NotificationCheckSupportLogWeldlog::class,
\App\Console\Commands\NotificationCheckPaintSystem::class,
\App\Console\Commands\NotificationCheckWeldlogTestDates::class,
\App\Console\Commands\NotificationCheckNDTRequestOverdue::class,
\App\Console\Commands\NotificationCheckTestLogPDF::class,
\App\Console\Commands\VerifyMechanicalSummaries::class,
\App\Console\Commands\SummaryCalculation::class,
\App\Console\Commands\CacheBladeViews::class,
\App\Console\Commands\NotificationCheckCalibrationDue::class,
\App\Console\Commands\NaksSync::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// Cache Blade Views - Run every 10 minutes
$schedule->command('cache:blade-views')
->everyTenMinutes()
->withoutOverlapping(10);
// CheckNDTReminders command removed - outdated checks (overdue, report missing, results pending)
// Notification checks - Run every 5 minutes (real-time notifications)
// All commands use incremental checking: first run scans all records, subsequent runs only check new records
// Log when schedule:run starts
$schedule->call(function () {
logSchedulerExecution('schedule_run_started', [
'run_time' => now()->toDateTimeString(),
]);
})->name('schedule-run-logger')->everyMinute()->withoutOverlapping(1);
// Helper function to add logging to scheduled commands
$addScheduledCommand = function($command, $schedule, $scheduleMethod, ...$args) {
$event = $schedule->command($command);
// Apply schedule method (everyFiveMinutes, cron, etc.)
if (method_exists($event, $scheduleMethod)) {
$event = $event->$scheduleMethod(...$args);
}
// Send output to log file instead of /dev/null
// This ensures before/after callbacks work correctly
$logFile = storage_path('logs/scheduler-' . date('Y-m-d') . '.log');
$event->sendOutputTo($logFile);
$event->appendOutputTo($logFile);
// Add before callback to log when command is scheduled to run
$event->before(function () use ($command) {
logSchedulerExecution('command_scheduled', [
'command' => $command,
'scheduled_time' => now()->toDateTimeString(),
]);
});
// Add after callback to log when command finishes
$event->after(function () use ($command) {
logSchedulerExecution('command_finished', [
'command' => $command,
'finished_time' => now()->toDateTimeString(),
]);
});
return $event;
};
$addScheduledCommand('notifications:check-deleted-joints', $schedule, 'everyFiveMinutes')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-repair-log-new-joint', $schedule, 'everyFiveMinutes')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-daily-repair-rate', $schedule, 'everyFiveMinutes')
->withoutOverlapping(10);
// --- Batch 2 (Minutes: 1, 6, 11, 16...) ---
$addScheduledCommand('notifications:check-line-list-missing-data', $schedule, 'cron', '1-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-pdf-documents', $schedule, 'cron', '1-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-weldlog-certificate', $schedule, 'cron', '1-59/5 * * * *')
->withoutOverlapping(10);
// --- Batch 3 (Minutes: 2, 7, 12, 17...) ---
$addScheduledCommand('notifications:check-incoming-control-certificate', $schedule, 'cron', '2-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-nde-matrix-discrepancies', $schedule, 'cron', '2-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-ndt-calculation', $schedule, 'cron', '2-59/5 * * * *')
->withoutOverlapping(10);
// --- Batch 4 (Minutes: 3, 8, 13, 18...) ---
$addScheduledCommand('notifications:check-manage-ndt-unnecessary', $schedule, 'cron', '3-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-support-log-weldlog', $schedule, 'cron', '3-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-paint-system-values', $schedule, 'cron', '3-59/5 * * * *')
->withoutOverlapping(10);
// --- Batch 5 (Minutes: 4, 9, 14, 19...) ---
$addScheduledCommand('notifications:check-weldlog-test-dates', $schedule, 'cron', '4-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-ndt-request-overdue', $schedule, 'cron', '4-59/5 * * * *')
->withoutOverlapping(10);
$addScheduledCommand('notifications:check-test-log-pdf', $schedule, 'cron', '4-59/5 * * * *')
->withoutOverlapping(10);
// Calibration notifications - due within 20 days (run in same batch)
$addScheduledCommand('notifications:check-calibration-due', $schedule, 'cron', '4-59/5 * * * *')
->withoutOverlapping(10);
$schedule->command('summary:calculation')
->hourly()
->withoutOverlapping(10);
// NAKS Multi-Module Cross-Site Sync - Run daily at 02:00
// Synchronizes all NAKS data (certificates, welders, consumables, experts, equipment)
// from all project sites
$schedule->command('naks:sync --module=all')
->hourly()
->withoutOverlapping(120)
->appendOutputTo(storage_path('logs/naks-sync.log'));
$schedule->command('telescope:prune')->daily();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}