* * For the full copyright and license information, please view * the LICENSE file that was distributed with this source code. */ namespace Config; use App\Jobs\BoundedQueueWorker; use CodeIgniter\Tasks\Config\Tasks as BaseTasks; use CodeIgniter\Tasks\Scheduler; class Tasks extends BaseTasks { /** * -------------------------------------------------------------------------- * Should performance metrics be logged * -------------------------------------------------------------------------- * * If true, will log the time it takes for each task to run. * Requires the settings table to have been created previously. */ public bool $logPerformance = false; /** * -------------------------------------------------------------------------- * Maximum performance logs * -------------------------------------------------------------------------- * * The maximum number of logs that should be saved per Task. * Lower numbers reduced the amount of database required to * store the logs. */ public int $maxLogsPerTask = 10; /** * Register any tasks within this method for the application. * Called by the TaskRunner. */ public function init(Scheduler $schedule) { // Heartbeat task: mode-agnostic, just logs whenever `tasks:run` executes it - // whether triggered by cron/Task Scheduler (auto), a manual `spark tasks:run` (manual), // or the JobRunner filter (web). $schedule->call(static function () { log_message('debug', 'Job Queue heartbeat: tasks:run executed at ' . date('c')); })->everyMinute()->named('jobs_heartbeat'); // Drains the core queues when Jobs mode is 'auto', so a single // `spark tasks:run` cron/Task Scheduler entry is enough - no separate // `queue:work` process needed alongside it. $schedule->call(static function () { $config = config(OSPOS::class)->settings; if (($config['jobs_mode'] ?? 'web') !== 'auto') { return; } $jobsConfig = config(Jobs::class); $maxSeconds = (int)($config['jobs_task_max_seconds'] ?? $jobsConfig->taskMaxSeconds); $deadline = microtime(true) + $maxSeconds; $worker = new BoundedQueueWorker($jobsConfig->coreQueues, $deadline); $worker->run(); })->everyMinute()->named('jobs_queue_worker'); } }