Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/BackgroundJob/IJob.php9
-rw-r--r--lib/public/BackgroundJob/IJobList.php5
-rw-r--r--lib/public/BackgroundJob/TimedJob.php32
3 files changed, 44 insertions, 2 deletions
diff --git a/lib/public/BackgroundJob/IJob.php b/lib/public/BackgroundJob/IJob.php
index 341ae2ac545..3c2da42bf88 100644
--- a/lib/public/BackgroundJob/IJob.php
+++ b/lib/public/BackgroundJob/IJob.php
@@ -35,6 +35,15 @@ use OCP\ILogger;
*/
interface IJob {
/**
+ * @since 24.0.0
+ */
+ public const TIME_INSENSITIVE = 0;
+ /**
+ * @since 24.0.0
+ */
+ public const TIME_SENSITIVE = 1;
+
+ /**
* Run the background job with the registered argument
*
* @param IJobList $jobList The job list that manages the state of this job
diff --git a/lib/public/BackgroundJob/IJobList.php b/lib/public/BackgroundJob/IJobList.php
index 9f3b485c280..eab37a03f36 100644
--- a/lib/public/BackgroundJob/IJobList.php
+++ b/lib/public/BackgroundJob/IJobList.php
@@ -85,10 +85,11 @@ interface IJobList {
/**
* get the next job in the list
*
+ * @param bool $onlyTimeSensitive
* @return \OCP\BackgroundJob\IJob|null
- * @since 7.0.0
+ * @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added
*/
- public function getNext();
+ public function getNext(bool $onlyTimeSensitive = false): ?IJob;
/**
* @param int $id
diff --git a/lib/public/BackgroundJob/TimedJob.php b/lib/public/BackgroundJob/TimedJob.php
index 2cc9ea8e293..579486f6fbf 100644
--- a/lib/public/BackgroundJob/TimedJob.php
+++ b/lib/public/BackgroundJob/TimedJob.php
@@ -38,6 +38,8 @@ use OCP\ILogger;
abstract class TimedJob extends Job {
/** @var int */
protected $interval = 0;
+ /** @var int */
+ protected $timeSensitivity = IJob::TIME_SENSITIVE;
/**
* set the interval for the job
@@ -51,6 +53,36 @@ abstract class TimedJob extends Job {
}
/**
+ * Whether the background job is time sensitive and needs to run soon after
+ * the scheduled interval, of if it is okay to be delayed until a later time.
+ *
+ * @return bool
+ * @since 24.0.0
+ */
+ public function isTimeSensitive(): bool {
+ return $this->timeSensitivity === IJob::TIME_SENSITIVE;
+ }
+
+ /**
+ * If your background job is not time sensitive (sending instant email
+ * notifications, etc.) it would be nice to set it to IJob::TIME_INSENSITIVE
+ * This way the execution can be delayed during high usage times.
+ *
+ * @param int $sensitivity
+ * @psalm-param IJob::TIME_* $sensitivity
+ * @return void
+ * @since 24.0.0
+ */
+ public function setTimeSensitivity(int $sensitivity): void {
+ if ($sensitivity !== IJob::TIME_SENSITIVE &&
+ $sensitivity !== IJob::TIME_INSENSITIVE) {
+ throw new \InvalidArgumentException('Invalid sensitivity');
+ }
+
+ $this->timeSensitivity = $sensitivity;
+ }
+
+ /**
* run the job if the last run is is more than the interval ago
*
* @param JobList $jobList