+
+ if (($delivery['failed'] < 3) || GServer::isReachableById($delivery['gsid'])) {
+ $priority = Worker::PRIORITY_HIGH;
+ } elseif ($delivery['failed'] < 6) {
+ $priority = Worker::PRIORITY_MEDIUM;
+ } elseif ($delivery['failed'] < 8) {
+ $priority = Worker::PRIORITY_LOW;
+ } else {
+ $priority = Worker::PRIORITY_NEGLIGIBLE;
+ }
+
+ if (Worker::add(['priority' => $priority, 'force_priority' => true], 'BulkDelivery', $delivery['gsid'])) {
+ Logger::info('Priority for BulkDelivery worker adjusted', ['gsid' => $delivery['gsid'], 'failed' => $delivery['failed'], 'priority' => $priority]);
+ }
+ }
+
+ // Optimizing this table only last seconds
+ if (DI::config()->get('system', 'optimize_tables')) {
+ Logger::info('Optimize start');
+ DBA::e("OPTIMIZE TABLE `delivery-queue`");
+ Logger::info('Optimize end');
+ }
+ }
+
+ /**
+ * Add missing "intro" records.
+ *
+ * @return void
+ */
+ private static function addIntros()
+ {
+ $contacts = DBA::p("SELECT `uid`, `id`, `created` FROM `contact` WHERE `rel` = ? AND `pending` AND NOT `id` IN (SELECT `contact-id` FROM `intro`)", Contact::FOLLOWER);
+ while ($contact = DBA::fetch($contacts)) {
+ $fields = [
+ 'uid' => $contact['uid'],
+ 'contact-id' => $contact['id'],
+ 'datetime' => $contact['created'],
+ 'hash' => Strings::getRandomHex()
+ ];
+ Logger::notice('Adding missing intro', ['fields' => $fields]);
+ DBA::insert('intro', $fields);