setInterval(300); $this->setTimeSensitivity(IJob::TIME_SENSITIVE); } protected function run($argument): void { $budget = PHP_SAPI === 'cli' ? 240.0 : 20.0; $deadline = microtime(true) + $budget; $this->startScheduled(); foreach ($this->runs->findRunning() as $run) { while (microtime(true) < $deadline && $run->getStatus() === 'running') { $run = $this->backups->step($run, min($deadline, microtime(true) + $budget)); } } } /** Daily schedule: appconfig ng_backup/schedule_time "HH:MM" (server time); empty = no schedule. */ private function startScheduled(): void { $at = $this->appConfig->getValueString(Application::APP_ID, 'schedule_time', ''); if (!preg_match('/^([01]\d|2[0-3]):[0-5]\d$/', $at)) { return; } $todayAt = strtotime(date('Y-m-d') . ' ' . $at); if (time() < $todayAt) { return; } foreach ($this->targets->list() as $t) { $last = $this->runs->lastFinished($t->getId(), BackupService::KIND_FULL); if ($this->runs->findRunning($t->getId()) !== [] || ($last !== null && $last->getStartedAt() >= $todayAt)) { continue; } try { $this->backups->start($t, 'scheduled'); } catch (\Throwable $e) { $this->logger->warning('NG Backup: scheduled backup to ' . $t->getName() . ' not started: ' . $e->getMessage()); } } } }