mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-11-08 23:43:32 -05:00
- Simplify 'auto' mode to run only `spark tasks:run` on cron/Task
Scheduler; new `jobs_queue_worker` task (app/Config/Tasks.php) now
drains core queues in-process using BoundedQueueWorker, so the
separate `queue:work` cron entry/Task Scheduler task and Docker
compose/sidecar commands are no longer needed (INSTALL.md).
- Extend BoundedQueueWorker to cover 'auto' mode alongside 'web' and
'manual', removing the old single-mode restriction in its docblock.
- Add job_log() helper (app/Helpers/job_helper.php) and
JobsFileHandler (app/Logging/JobsFileHandler.php) to write job
activity to per-queue log files (jobsLog-{queue}-{date}.log)
instead of the shared application log; register 'job' helper in
app/Config/Autoload.php.
- Route job-related log_message() calls in BoundedQueueWorker,
CustomerCsvRowProcessor, and ItemCsvRowProcessor to job_log(),
and add extra per-row import logging (item id/name/barcode) for
easier troubleshooting of CSV imports.
Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
75 lines
2.6 KiB
PHP
75 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* This file is part of CodeIgniter Tasks.
|
|
*
|
|
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
|
*
|
|
* 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');
|
|
}
|
|
}
|