123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- declare(strict_types=1);
- namespace OCP\BackgroundJob;
- use OCP\ILogger;
- abstract class TimedJob extends Job {
- protected int $interval = 0;
- protected int $timeSensitivity = IJob::TIME_SENSITIVE;
-
- public function setInterval(int $seconds) {
- $this->interval = $seconds;
- }
-
- public function isTimeSensitive(): bool {
- return $this->timeSensitivity === IJob::TIME_SENSITIVE;
- }
-
- public function setTimeSensitivity(int $sensitivity): void {
- if ($sensitivity !== IJob::TIME_SENSITIVE &&
- $sensitivity !== IJob::TIME_INSENSITIVE) {
- throw new \InvalidArgumentException('Invalid sensitivity');
- }
- $this->timeSensitivity = $sensitivity;
- }
-
- final public function execute(IJobList $jobList, ILogger $logger = null) {
- $this->start($jobList);
- }
-
- final public function start(IJobList $jobList): void {
- if (($this->time->getTime() - $this->lastRun) > $this->interval) {
- parent::start($jobList);
- }
- }
- }
|