Randomize the times of the data update cronjobs
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 23 Feb 2022 15:55:52 +0000 (16:55 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 24 Feb 2022 08:35:47 +0000 (09:35 +0100)
This prevents requests spikes at package servers at 2:00 UTC every other day.

With the time of the update cronjobs randomized, the package list updater will
now run daily.

com.woltlab.wcf/cronjob.xml
wcfsetup/install/files/acp/post_install.php

index 2a52565abf4990f1495a0dcba94fed77c776fd85..fc6c12cc83f34c27641f553edd445f69ddd8770b 100644 (file)
@@ -7,7 +7,7 @@
                        <description language="de">Aktualisiert Paket-Informationen</description>
                        <startminute>0</startminute>
                        <starthour>2</starthour>
-                       <startdom>*/2</startdom>
+                       <startdom>*</startdom>
                        <startmonth>*</startmonth>
                        <startdow>*</startdow>
                        <canbedisabled>0</canbedisabled>
index e6c173ba5f38eceb4d9c16f996c664f44654526f..9956a20fa3494b7e529e860482e742fa08f5df2a 100644 (file)
@@ -2,6 +2,7 @@
 
 use wcf\data\category\CategoryEditor;
 use wcf\data\object\type\ObjectTypeCache;
+use wcf\data\package\PackageCache;
 use wcf\data\user\UserEditor;
 use wcf\data\user\UserProfileAction;
 use wcf\system\WCF;
@@ -30,3 +31,45 @@ CategoryEditor::create([
     'title' => 'Default Category',
     'time' => TIME_NOW,
 ]);
+
+// Randomize the times of the package list update and robot list update cronjobs.
+$sql = "UPDATE  wcf1_cronjob
+        SET     startMinute = ?,
+                startHour = ?,
+                startDom = ?,
+                startMonth = ?,
+                startDow = ?,
+                lastExec = ?,
+                nextExec = ?,
+                afterNextExec = ?
+        WHERE   packageiD = ?
+            AND cronjobName = ?";
+$statement = WCF::getDB()->prepare($sql);
+$statement->execute([
+    \random_int(0, 59),
+    \random_int(0, 23),
+    '*',
+    '*',
+    '*',
+
+    0,
+    \TIME_NOW,
+    0,
+
+    $this->installation->getPackageID(),
+    'com.woltlab.wcf.refreshPackageUpdates',
+]);
+$statement->execute([
+    \random_int(0, 59),
+    \random_int(0, 23),
+    \random_int(1, 15),
+    '*',
+    '*',
+
+    0,
+    \TIME_NOW,
+    0,
+
+    $this->installation->getPackageID(),
+    'com.woltlab.wcf.refreshSearchRobots',
+]);