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:
-rw-r--r--config/config.sample.php14
-rw-r--r--cron.php24
2 files changed, 37 insertions, 1 deletions
diff --git a/config/config.sample.php b/config/config.sample.php
index f80904588e3..b099b08f78c 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -1217,6 +1217,20 @@ $CONFIG = [
*/
'maintenance' => false,
+/**
+ * UTC Hour for maintenance windows
+ *
+ * Some background jobs only run once a day. When an hour is defined for this config,
+ * the background jobs which advertise themselves as not time sensitive will be
+ * delayed during the "working" hours and only run in the 4 hours after the given time.
+ * This is e.g. used for activity expiration, suspicious login training and update checks.
+ *
+ * A value of 1 e.g. will only run these background jobs between 01:00am UTC and 05:00am UTC.
+ *
+ * Defaults to ``100`` which disables the feature
+ */
+'maintenance_window_start' => 1,
+
/**
* SSL
diff --git a/cron.php b/cron.php
index aa14e17709e..5095a2c7574 100644
--- a/cron.php
+++ b/cron.php
@@ -110,6 +110,28 @@ try {
$config->setAppValue('core', 'backgroundjobs_mode', 'cron');
}
+ // Low-load hours
+ $onlyTimeSensitive = false;
+ $startHour = $config->getSystemValueInt('maintenance_window_start', 100);
+ if ($startHour <= 23) {
+ $date = new \DateTime('now', new \DateTimeZone('UTC'));
+ $currentHour = (int) $date->format('G');
+ $endHour = $startHour + 4;
+
+ if ($startHour <= 20) {
+ // Start time: 01:00
+ // End time: 05:00
+ // Only run sensitive tasks when it's before the start or after the end
+ $onlyTimeSensitive = $currentHour < $startHour || $currentHour > $endHour;
+ } else {
+ // Start time: 23:00
+ // End time: 03:00
+ $endHour -= 24; // Correct the end time from 27:00 to 03:00
+ // Only run sensitive tasks when it's after the end and before the start
+ $onlyTimeSensitive = $currentHour > $endHour && $currentHour < $startHour;
+ }
+ }
+
// Work
$jobList = \OC::$server->getJobList();
@@ -119,7 +141,7 @@ try {
$endTime = time() + 14 * 60;
$executedJobs = [];
- while ($job = $jobList->getNext()) {
+ while ($job = $jobList->getNext($onlyTimeSensitive)) {
if (isset($executedJobs[$job->getId()])) {
$jobList->unlockJob($job);
break;