Files
nextcloud-workflow-deck-aut…/lib/BackgroundJob/RunWorkflowsJob.php
T
Patrick Niebeling b37a0db123
Build package / php-lint (8.2) (push) Successful in 48s
Build package / php-lint (8.3) (push) Successful in 45s
Build package / php-lint (8.4) (push) Successful in 47s
Build package / xml-lint (push) Successful in 13s
Build package / unit-tests (push) Successful in 43s
Build package / package (push) Canceled after 0s
Make the background job time-sensitive so cron actually runs it
The job was registered but never executed: `background-job:list` kept
showing last_run = 1970-01-01. It was marked TIME_INSENSITIVE, and
OC\Core\Service\CronService::runCli() reads `maintenance_window_start` and
calls jobList->getNext($onlyTimeSensitive = true) whenever the current UTC
hour is outside [start, start+4] -- so with a maintenance window configured,
time-insensitive jobs are skipped for the other 20 hours of the day.

A job whose entire purpose is a 5-minute (now configurable down to 60s)
reaction time is time-sensitive by definition.

Also fix the occ invocation in README.md and CLAUDE.md: background-job:worker
takes job classes, not an app id, so the documented
`background-job:worker workflow_deck_automation` matched nothing.
2026-08-13 14:48:13 +02:00

58 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\WorkflowDeckAutomation\BackgroundJob;
use OCA\WorkflowDeckAutomation\Service\WorkflowRunner;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\TimedJob;
use OCP\IConfig;
class RunWorkflowsJob extends TimedJob {
/**
* config.php key holding how often (in seconds) workflows are checked.
*/
public const INTERVAL_CONFIG_KEY = 'workflow_deck_automation.interval';
public const DEFAULT_INTERVAL = 5 * 60;
/**
* Nextcloud's cron itself only ticks every 5 minutes by default, so
* anything below a minute would only add load without running more
* often. Values under this are clamped rather than rejected.
*/
public const MINIMUM_INTERVAL = 60;
public function __construct(
ITimeFactory $time,
IConfig $config,
private WorkflowRunner $runner,
) {
parent::__construct($time);
// TimedJob compares against this value on every cron pass, so a
// changed config.php takes effect on the next pass — no occ command
// and no re-registration of the job needed.
$this->setInterval(self::resolveInterval($config));
// Must stay TIME_SENSITIVE. If `maintenance_window_start` is set in
// config.php — and Nextcloud's admin overview actively nags admins
// to set it — CronService only picks up TIME_INSENSITIVE jobs during
// those 4 hours and skips them for the rest of the day. A job whose
// whole point is a 5-minute (configurable down to 60s) reaction time
// would then run a handful of times per night and look completely
// dead in between.
$this->setTimeSensitivity(IJob::TIME_SENSITIVE);
$this->setAllowParallelRuns(false);
}
private static function resolveInterval(IConfig $config): int {
$interval = $config->getSystemValueInt(self::INTERVAL_CONFIG_KEY, self::DEFAULT_INTERVAL);
return max(self::MINIMUM_INTERVAL, $interval);
}
protected function run($argument): void {
$this->runner->run();
}
}