]> source.dussan.org Git - nextcloud-server.git/commitdiff
Mark DAV background jobs as time sensitive/insensitive 31316/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Tue, 22 Feb 2022 10:24:38 +0000 (11:24 +0100)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Tue, 22 Feb 2022 12:55:06 +0000 (13:55 +0100)
* As a bonus they are now all using OCP base classes
* Strict typing is now enforced

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
13 files changed:
apps/dav/lib/BackgroundJob/CalendarRetentionJob.php
apps/dav/lib/BackgroundJob/CleanupDirectLinksJob.php
apps/dav/lib/BackgroundJob/CleanupInvitationTokenJob.php
apps/dav/lib/BackgroundJob/EventReminderJob.php
apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php
apps/dav/lib/BackgroundJob/RegisterRegenerateBirthdayCalendars.php
apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php
apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php
apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php
apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
apps/dav/tests/unit/BackgroundJob/RegisterRegenerateBirthdayCalendarsTest.php
apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php
apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php

index 6be6d7c3cd1e398af306a204dad438efeb0947c8..b57ed07d5c24790270868d40b02619738379cc5e 100644 (file)
@@ -40,6 +40,7 @@ class CalendarRetentionJob extends TimedJob {
 
                // Run four times a day
                $this->setInterval(6 * 60 * 60);
+               $this->setTimeSensitivity(self::TIME_SENSITIVE);
        }
 
        protected function run($argument): void {
index 6c10a05f9a5391ce98854ab463f700507687f68a..073fc53e07ad3545646d84baa23292592bd93004 100644 (file)
@@ -26,26 +26,25 @@ declare(strict_types=1);
  */
 namespace OCA\DAV\BackgroundJob;
 
-use OC\BackgroundJob\TimedJob;
 use OCA\DAV\Db\DirectMapper;
 use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
 
 class CleanupDirectLinksJob extends TimedJob {
-       /** @var ITimeFactory */
-       private $timeFactory;
-
        /** @var DirectMapper */
        private $mapper;
 
        public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) {
-               $this->setInterval(60 * 60 * 24);
-
-               $this->timeFactory = $timeFactory;
+               parent::__construct($timeFactory);
                $this->mapper = $mapper;
+
+               // Run once a day at off-peak time
+               $this->setInterval(24 * 60 * 60);
+               $this->setTimeSensitivity(self::TIME_INSENSITIVE);
        }
 
        protected function run($argument) {
                // Delete all shares expired 24 hours ago
-               $this->mapper->deleteExpired($this->timeFactory->getTime() - 60 * 60 * 24);
+               $this->mapper->deleteExpired($this->time->getTime() - 60 * 60 * 24);
        }
 }
index 9621b5d9499e31a51153bbeb44a0241145fd79f4..6339e721c9304efb8c54fb9f1edd85ef916f723e 100644 (file)
@@ -26,8 +26,8 @@ declare(strict_types=1);
  */
 namespace OCA\DAV\BackgroundJob;
 
-use OC\BackgroundJob\TimedJob;
 use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
 use OCP\IDBConnection;
 
 class CleanupInvitationTokenJob extends TimedJob {
@@ -35,21 +35,20 @@ class CleanupInvitationTokenJob extends TimedJob {
        /** @var IDBConnection  */
        private $db;
 
-       /** @var ITimeFactory */
-       private $timeFactory;
-
-       public function __construct(IDBConnection $db, ITimeFactory $timeFactory) {
+       public function __construct(IDBConnection $db, ITimeFactory $time) {
+               parent::__construct($time);
                $this->db = $db;
-               $this->timeFactory = $timeFactory;
 
-               $this->setInterval(60 * 60 * 24);
+               // Run once a day at off-peak time
+               $this->setInterval(24 * 60 * 60);
+               $this->setTimeSensitivity(self::TIME_INSENSITIVE);
        }
 
        public function run($argument) {
                $query = $this->db->getQueryBuilder();
                $query->delete('calendar_invitations')
                        ->where($query->expr()->lt('expiration',
-                               $query->createNamedParameter($this->timeFactory->getTime())))
+                               $query->createNamedParameter($this->time->getTime())))
                        ->execute();
        }
 }
index b67a5d970bb65d378c882578cd8d326ed535d31f..ab7dadd8c0b2f2e8c11332b59002ab76625550eb 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright Copyright (c) 2016 Thomas Citharel <nextcloud@tcit.fr>
  *
@@ -23,8 +26,9 @@
  */
 namespace OCA\DAV\BackgroundJob;
 
-use OC\BackgroundJob\TimedJob;
 use OCA\DAV\CalDAV\Reminder\ReminderService;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
 use OCP\IConfig;
 
 class EventReminderJob extends TimedJob {
@@ -35,17 +39,16 @@ class EventReminderJob extends TimedJob {
        /** @var IConfig */
        private $config;
 
-       /**
-        * EventReminderJob constructor.
-        *
-        * @param ReminderService $reminderService
-        * @param IConfig $config
-        */
-       public function __construct(ReminderService $reminderService, IConfig $config) {
+       public function __construct(ITimeFactory $time,
+                                                               ReminderService $reminderService,
+                                                               IConfig $config) {
+               parent::__construct($time);
                $this->reminderService = $reminderService;
                $this->config = $config;
-               /** Run every 5 minutes */
-               $this->setInterval(5);
+
+               // Run every 5 minutes
+               $this->setInterval(5 * 60);
+               $this->setTimeSensitivity(self::TIME_SENSITIVE);
        }
 
        /**
index 2fdb761793783910c12121b7adcc050b9a7b8cf6..a338a172d66f38735ec589a6c560e79fab867306 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright 2017 Georg Ehrke <oc.list@georgehrke.com>
  *
@@ -22,8 +25,9 @@
  */
 namespace OCA\DAV\BackgroundJob;
 
-use OC\BackgroundJob\QueuedJob;
 use OCA\DAV\CalDAV\BirthdayService;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\QueuedJob;
 use OCP\IConfig;
 
 class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
@@ -34,14 +38,11 @@ class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
        /** @var IConfig */
        private $config;
 
-       /**
-        * GenerateAllBirthdayCalendarsBackgroundJob constructor.
-        *
-        * @param BirthdayService $birthdayService
-        * @param IConfig $config
-        */
-       public function __construct(BirthdayService $birthdayService,
+       public function __construct(ITimeFactory $time,
+                                                               BirthdayService $birthdayService,
                                                                IConfig $config) {
+               parent::__construct($time);
+
                $this->birthdayService = $birthdayService;
                $this->config = $config;
        }
index 0813de7d1ad9550d8d2ce8738d38d8577b97d9c3..85da81b3b91fd25ede87620f0ed57844a3fcd20f 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright 2019 Georg Ehrke <oc.list@georgehrke.com>
  *
index 9b3aeac59045c7441a2b7e05bf2f3a5574f19533..f7addd58248c7d21d415b7e0eab7f51058a7dfb4 100644 (file)
@@ -28,8 +28,9 @@ declare(strict_types=1);
 
 namespace OCA\DAV\BackgroundJob;
 
-use OC\BackgroundJob\TimedJob;
 use OCA\DAV\CalDAV\CalDavBackend;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
 use OCP\Calendar\BackendTemporarilyUnavailableException;
 use OCP\Calendar\IMetadataProvider;
 use OCP\Calendar\Resource\IBackend as IResourceBackend;
@@ -53,17 +54,20 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob {
        /** @var CalDavBackend */
        private $calDavBackend;
 
-       public function __construct(IResourceManager $resourceManager,
+       public function __construct(ITimeFactory $time,
+                                                               IResourceManager $resourceManager,
                                                                IRoomManager $roomManager,
                                                                IDBConnection $dbConnection,
                                                                CalDavBackend $calDavBackend) {
+               parent::__construct($time);
                $this->resourceManager = $resourceManager;
                $this->roomManager = $roomManager;
                $this->dbConnection = $dbConnection;
                $this->calDavBackend = $calDavBackend;
 
-               // run once an hour
+               // Run once an hour
                $this->setInterval(60 * 60);
+               $this->setTimeSensitivity(self::TIME_SENSITIVE);
        }
 
        /**
index f9276b61956dfa2a2e7144d55759e93dc8288651..ed3c324e7107372e2d53fa4af350864c493dd284 100644 (file)
@@ -30,27 +30,37 @@ namespace OCA\DAV\Tests\unit\BackgroundJob;
 
 use OCA\DAV\BackgroundJob\EventReminderJob;
 use OCA\DAV\CalDAV\Reminder\ReminderService;
+use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
 use Test\TestCase;
 
 class EventReminderJobTest extends TestCase {
 
-       /** @var ReminderService|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var ITimeFactory|MockObject */
+       private $time;
+
+       /** @var ReminderService|MockObject */
        private $reminderService;
 
-       /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var IConfig|MockObject */
        private $config;
 
-       /** @var EventReminderJob|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var EventReminderJob|MockObject */
        private $backgroundJob;
 
        protected function setUp(): void {
                parent::setUp();
 
+               $this->time = $this->createMock(ITimeFactory::class);
                $this->reminderService = $this->createMock(ReminderService::class);
                $this->config = $this->createMock(IConfig::class);
 
-               $this->backgroundJob = new EventReminderJob($this->reminderService, $this->config);
+               $this->backgroundJob = new EventReminderJob(
+                       $this->time,
+                       $this->reminderService,
+                       $this->config,
+               );
        }
 
        public function data(): array {
index 6c6e02ce71734221551c79880d8fc06ce1114735..e0601c5c71ab2c3125f42d490abcacb6556f7ed7 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright Copyright (c) 2017, Georg Ehrke
  *
@@ -27,15 +30,20 @@ namespace OCA\DAV\Tests\unit\BackgroundJob;
 
 use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
 use OCA\DAV\CalDAV\BirthdayService;
+use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
 use Test\TestCase;
 
 class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {
 
-       /** @var BirthdayService | \PHPUnit\Framework\MockObject\MockObject */
+       /** @var ITimeFactory|MockObject */
+       private $time;
+
+       /** @var BirthdayService | MockObject */
        private $birthdayService;
 
-       /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
+       /** @var IConfig | MockObject */
        private $config;
 
        /** @var \OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob */
@@ -44,11 +52,15 @@ class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {
        protected function setUp(): void {
                parent::setUp();
 
+               $this->time = $this->createMock(ITimeFactory::class);
                $this->birthdayService = $this->createMock(BirthdayService::class);
                $this->config = $this->createMock(IConfig::class);
 
                $this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob(
-                       $this->birthdayService, $this->config);
+                       $this->time,
+                       $this->birthdayService,
+                       $this->config,
+               );
        }
 
        public function testRun() {
index eba2a21f76189a755e59ce20a669355fdf35aeff..360c4c791c70433a50f48f20753fa3db2437e0d4 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright Copyright (c) 2018, Georg Ehrke
  *
index f3b1878a8339241f86dd23dff9704443b043ae21..00931d53f64af25b50fb303bb7164b8831c9011d 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright 2019 Georg Ehrke <oc.list@georgehrke.com>
  *
@@ -45,9 +48,6 @@ class RegisterRegenerateBirthdayCalendarsTest extends TestCase {
        /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */
        private $jobList;
 
-       /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
-       private $config;
-
        /** @var RegisterRegenerateBirthdayCalendars */
        private $backgroundJob;
 
@@ -57,10 +57,12 @@ class RegisterRegenerateBirthdayCalendarsTest extends TestCase {
                $this->time = $this->createMock(ITimeFactory::class);
                $this->userManager = $this->createMock(IUserManager::class);
                $this->jobList = $this->createMock(IJobList::class);
-               $this->config = $this->createMock(IConfig::class);
 
-               $this->backgroundJob = new RegisterRegenerateBirthdayCalendars($this->time,
-                       $this->userManager, $this->jobList);
+               $this->backgroundJob = new RegisterRegenerateBirthdayCalendars(
+                       $this->time,
+                       $this->userManager,
+                       $this->jobList
+               );
        }
 
        public function testRun() {
index 5974d0dec999a7dd6356fcb24345e395ad592a2b..59b68452862ed267f9a9cf3b2f37ac559a8c6d5d 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright Copyright (c) 2018, Georg Ehrke
  *
@@ -29,12 +32,14 @@ namespace OCA\DAV\Tests\unit\BackgroundJob;
 use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob;
 
 use OCA\DAV\CalDAV\CalDavBackend;
+use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\Calendar\BackendTemporarilyUnavailableException;
 use OCP\Calendar\IMetadataProvider;
 use OCP\Calendar\Resource\IBackend;
 use OCP\Calendar\Resource\IManager as IResourceManager;
 use OCP\Calendar\Resource\IResource;
 use OCP\Calendar\Room\IManager as IRoomManager;
+use PHPUnit\Framework\MockObject\MockObject;
 use Test\TestCase;
 
 interface tmpI extends IResource, IMetadataProvider {
@@ -42,28 +47,36 @@ interface tmpI extends IResource, IMetadataProvider {
 
 class UpdateCalendarResourcesRoomsBackgroundJobTest extends TestCase {
 
-       /** @var UpdateCalendarResourcesRoomsBackgroundJob */
-       private $backgroundJob;
+       /** @var ITimeFactory|MockObject */
+       private $time;
 
-       /** @var IResourceManager | \PHPUnit\Framework\MockObject\MockObject */
+       /** @var IResourceManager|MockObject */
        private $resourceManager;
 
-       /** @var IRoomManager | \PHPUnit\Framework\MockObject\MockObject */
+       /** @var IRoomManager|MockObject */
        private $roomManager;
 
-       /** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject */
+       /** @var CalDavBackend|MockObject */
        private $calDavBackend;
 
+       /** @var UpdateCalendarResourcesRoomsBackgroundJob */
+       private $backgroundJob;
+
        protected function setUp(): void {
                parent::setUp();
 
+               $this->time = $this->createMock(ITimeFactory::class);
                $this->resourceManager = $this->createMock(IResourceManager::class);
                $this->roomManager = $this->createMock(IRoomManager::class);
                $this->calDavBackend = $this->createMock(CalDavBackend::class);
 
                $this->backgroundJob = new UpdateCalendarResourcesRoomsBackgroundJob(
-                       $this->resourceManager, $this->roomManager, self::$realDatabase,
-                       $this->calDavBackend);
+                       $this->time,
+                       $this->resourceManager,
+                       $this->roomManager,
+                       self::$realDatabase,
+                       $this->calDavBackend
+               );
        }
 
        protected function tearDown(): void {
index f631abaabe0292c0aca6ed15133d8eaf76e6829b..cf0691de3ac15ec57b38660202498707588c7d03 100644 (file)
@@ -56,8 +56,8 @@ class RetryJob extends Job {
 
 
        public function __construct(Notifications $notifications,
-                                                               ITimeFactory $timeFactory) {
-               parent::__construct($timeFactory);
+                                                               ITimeFactory $time) {
+               parent::__construct($time);
                $this->notifications = $notifications;
        }