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:
authorJoas Schilling <coding@schilljs.com>2022-01-31 19:59:09 +0300
committerJoas Schilling <coding@schilljs.com>2022-02-07 15:54:54 +0300
commit3fd55cb4df80b6434cc5f028f80f1419b3f79202 (patch)
treecdfdb4ee1a290b2a79da940f6ad65ba607a81ac9 /cron.php
parentb765f79368885ace29d8cd122144a1357435cfbb (diff)
Allow sysadmins to define a maintenance window where heavier jobs can run
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'cron.php')
-rw-r--r--cron.php24
1 files changed, 23 insertions, 1 deletions
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;