From 07aedb47fceb4c67a2edc5c7bcab65d649a2a4ba Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Feb 2022 13:49:28 +0100 Subject: [PATCH 1/3] Document admin config for maintenance_window_start Signed-off-by: Joas Schilling --- .../background_jobs_configuration.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/admin_manual/configuration_server/background_jobs_configuration.rst b/admin_manual/configuration_server/background_jobs_configuration.rst index 3b942df34..a28fe1e67 100644 --- a/admin_manual/configuration_server/background_jobs_configuration.rst +++ b/admin_manual/configuration_server/background_jobs_configuration.rst @@ -19,12 +19,17 @@ externally mounted file systems. Parameters ---------- -In the admin settings menu you can configure how cron-jobs should be executed. -You can choose between the following options: -- AJAX -- Webcron -- Cron +``maintenance_window_start`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In the ``config/config.php`` file you can specify this config. +Some background jobs only run once a day. When an hour is defined (timezone is UTC) +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. Cron jobs --------- @@ -115,7 +120,7 @@ This approach requires two files: **nextcloudcron.service** and **nextcloudcron. Replace the user ``www-data`` with the user of your http server and ``/var/www/nextcloud/cron.php`` with the location of **cron.php** in your nextcloud directory. -The ``KillMode=process`` setting is necessary for external programs that are started by the cron job to keep running after the cron job has finished. +The ``KillMode=process`` setting is necessary for external programs that are started by the cron job to keep running after the cron job has finished. Note that the **.service** unit file does not need an ``[Install]`` section. Please check your setup because we recommended it in earlier versions of this admin manual. From ce51b05458d7f9ad91ffde756d69c6605b4ff0d6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Feb 2022 14:03:37 +0100 Subject: [PATCH 2/3] Add section to the dev docs as well Signed-off-by: Joas Schilling --- developer_manual/basics/backgroundjobs.rst | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/developer_manual/basics/backgroundjobs.rst b/developer_manual/basics/backgroundjobs.rst index 6042f7e45..3d1c4b8bd 100644 --- a/developer_manual/basics/backgroundjobs.rst +++ b/developer_manual/basics/backgroundjobs.rst @@ -62,6 +62,25 @@ to pass on to the service to run the background job. The ``run`` function is the main thing you need to implement and where all the logic happens. +Heavy load and time insensitive +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When the background job can impact the performance of the instance and is not time sensitive, +e.g. when clearing old data, running training of AI models or similar things, consider flagging +it as time insensitive in the constructor. + +.. code-block:: php + + - OCA\MyApp\Cron\SomeTask + OCA\MyApp\Cron\SomeTask This will on install/update of the application add the job ``OCA\MyApp\Cron\SomeTask``. From 83b5f104a02677994514fe514ac15e64e3ee0efd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Feb 2022 14:15:31 +0100 Subject: [PATCH 3/3] Use "$this->" Signed-off-by: Joas Schilling --- developer_manual/basics/backgroundjobs.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/developer_manual/basics/backgroundjobs.rst b/developer_manual/basics/backgroundjobs.rst index 3d1c4b8bd..5e4cfe61a 100644 --- a/developer_manual/basics/backgroundjobs.rst +++ b/developer_manual/basics/backgroundjobs.rst @@ -43,7 +43,7 @@ your job class of choice. $this->myService = $service; // Run once an hour - parent::setInterval(3600); + $this->setInterval(3600); } protected function run($arguments) { @@ -65,18 +65,18 @@ logic happens. Heavy load and time insensitive ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -When the background job can impact the performance of the instance and is not time sensitive, -e.g. when clearing old data, running training of AI models or similar things, consider flagging -it as time insensitive in the constructor. +When the background job is a ``\OCP\BackgroundJob\TimedJob`` and can impact the performance of +the instance and is not time sensitive, e.g. clearing old data, running training of AI models +or similar things, consider flagging it as time insensitive in the constructor. .. code-block:: php setInterval(24 * 3600); // Delay until low-load time - parent::setTimeSensitivity(IJob::TIME_INSENSITIVE); + $this->setTimeSensitivity(\OCP\BackgroundJob\IJob::TIME_INSENSITIVE); This allows the Nextcloud to delay the job until a given nightly time window so the users are not that impacted by the heavy load of the background job.