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>
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Logging;
|
|
|
|
use CodeIgniter\Log\Handlers\FileHandler;
|
|
use DateTime;
|
|
|
|
/**
|
|
* Writes job queue log entries to a per-queue file (jobsLog-{queue}-{date}.log)
|
|
* instead of CI4 FileHandler's shared log-{date}.log, so routine job activity
|
|
* doesn't clog the main application log.
|
|
*/
|
|
class JobsFileHandler extends FileHandler
|
|
{
|
|
public function __construct(array $config, private readonly string $queueName)
|
|
{
|
|
parent::__construct($config);
|
|
}
|
|
|
|
public function handle($level, $message): bool
|
|
{
|
|
$filepath = $this->path . 'jobsLog-' . $this->queueName . '-' . date('Y-m-d') . '.' . $this->fileExtension;
|
|
|
|
$msg = '';
|
|
|
|
$newfile = false;
|
|
if (! is_file($filepath)) {
|
|
$newfile = true;
|
|
|
|
if ($this->fileExtension === 'php') {
|
|
$msg .= "<?php defined('SYSTEMPATH') || exit('No direct script access allowed'); ?>\n\n";
|
|
}
|
|
}
|
|
|
|
if (! $fp = @fopen($filepath, 'ab')) {
|
|
return false;
|
|
}
|
|
|
|
if (str_contains($this->dateFormat, 'u')) {
|
|
$microtimeFull = microtime(true);
|
|
$microtimeShort = sprintf('%06d', ($microtimeFull - floor($microtimeFull)) * 1_000_000);
|
|
$date = new DateTime(date('Y-m-d H:i:s.' . $microtimeShort, (int)$microtimeFull));
|
|
$date = $date->format($this->dateFormat);
|
|
} else {
|
|
$date = date($this->dateFormat);
|
|
}
|
|
|
|
$msg .= strtoupper($level) . ' - ' . $date . ' --> ' . $message . "\n";
|
|
|
|
flock($fp, LOCK_EX);
|
|
|
|
$result = null;
|
|
|
|
for ($written = 0, $length = strlen($msg); $written < $length; $written += $result) {
|
|
if (($result = fwrite($fp, substr($msg, $written))) === false) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
flock($fp, LOCK_UN);
|
|
fclose($fp);
|
|
|
|
if ($newfile) {
|
|
@chmod($filepath, $this->filePermissions);
|
|
}
|
|
|
|
return is_int($result);
|
|
}
|
|
}
|