]> git.mxchange.org Git - friendica.git/commitdiff
Delivery count now counts the failed delivery attempts as well
authorMichael <heluecht@pirati.ca>
Tue, 20 Aug 2019 07:39:13 +0000 (07:39 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 20 Aug 2019 07:39:13 +0000 (07:39 +0000)
database.sql
src/Core/Worker.php
src/Model/Item.php
src/Model/ItemDeliveryData.php
src/Object/Post.php
src/Worker/APDelivery.php
src/Worker/Delivery.php
static/dbstructure.config.php

index deaec5a24b2423af3b100a7f2f22acab2a7b8a1a..c7d37a413440b90710f9a12c3cec2a5df4e7b753 100644 (file)
@@ -1,9 +1,23 @@
 -- ------------------------------------------
--- Friendica 2019.09-dev (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1319
+-- Friendica 2019.09-rc (Dalmatian Bellflower)
+-- DB_UPDATE_VERSION 1321
 -- ------------------------------------------
 
 
+--
+-- TABLE 2fa_app_specific_password
+--
+CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` (
+       `id` mediumint unsigned NOT NULL auto_increment COMMENT 'Password ID for revocation',
+       `uid` mediumint unsigned NOT NULL COMMENT 'User ID',
+       `description` varchar(255) COMMENT 'Description of the usage of the password',
+       `hashed_password` varchar(255) NOT NULL COMMENT 'Hashed password',
+       `generated` datetime NOT NULL COMMENT 'Datetime the password was generated',
+       `last_used` datetime COMMENT 'Datetime the password was last used',
+        PRIMARY KEY(`id`),
+        INDEX `uid_description` (`uid`,`description`)
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password';
+
 --
 -- TABLE 2fa_recovery_codes
 --
@@ -680,6 +694,7 @@ CREATE TABLE IF NOT EXISTS `item-delivery-data` (
        `inform` mediumtext COMMENT 'Additional receivers of the linked item',
        `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
        `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
+       `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
        `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
        `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
        `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
index 037590c90d7783e025bdf492353114b34972bb73..3533f24e45e8b3df00802ece0cc82584b0a1d112 100644 (file)
@@ -1222,11 +1222,12 @@ class Worker
 
        /**
         * Defers the current worker entry
+        * @return boolean had the entry been deferred?
         */
        public static function defer()
        {
                if (empty(BaseObject::getApp()->queue)) {
-                       return;
+                       return false;
                }
 
                $queue = BaseObject::getApp()->queue;
@@ -1241,7 +1242,7 @@ class Worker
 
                if ($new_retrial > $max_level) {
                        Logger::info('The task exceeded the maximum retry count', ['id' => $id, 'max_level' => $max_level, 'retrial' => $new_retrial]);
-                       return;
+                       return false;
                }
 
                // Calculate the delay until the next trial
@@ -1263,6 +1264,8 @@ class Worker
                DBA::update('workerqueue', $fields, ['id' => $id]);
                self::$db_duration += (microtime(true) - $stamp);
                self::$db_duration_write += (microtime(true) - $stamp);
+
+               return true;
        }
 
        /**
index 8ac88e96db30a9d00e8ca54d05442e1bab0dce93..3a421e96c43508d8ad598cc1419ae4cf4707f1ea 100644 (file)
@@ -59,7 +59,7 @@ class Item extends BaseObject
                'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
                'event-summary', 'event-desc', 'event-location', 'event-type',
                'event-nofinish', 'event-adjust', 'event-ignore', 'event-id',
-               'delivery_queue_count', 'delivery_queue_done'
+               'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed'
        ];
 
        // Field list that is used to deliver items via the protocols
index 1d5c37de2d0164dc19e699a4a74602a02cdaec54..f007537f99c02d687754ae50af8dfaf24996b779 100644 (file)
@@ -21,6 +21,7 @@ class ItemDeliveryData
                // New delivery fields with virtual field name in item fields
                'queue_count' => 'delivery_queue_count',
                'queue_done'  => 'delivery_queue_done',
+               'queue_failed'  => 'delivery_queue_failed',
        ];
 
        const ACTIVITYPUB = 1;
@@ -88,6 +89,20 @@ class ItemDeliveryData
                return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `iid` = ?', $item_id);
        }
 
+       /**
+        * Increments the queue_failed for the given item ID.
+        *
+        * Avoids racing condition between multiple delivery threads.
+        *
+        * @param integer $item_id
+        * @return bool
+        * @throws \Exception
+        */
+       public static function incrementQueueFailed($item_id)
+       {
+               return DBA::e('UPDATE `item-delivery-data` SET `queue_failed` = `queue_failed` + 1 WHERE `iid` = ?', $item_id);
+       }
+
        /**
         * Insert a new item delivery data entry
         *
index 173b1e53af6a86eecfda3abfb6c70c3d7e9c252f..7f9f84b546c678c274db0a76f1ffa0620b271af8 100644 (file)
@@ -432,7 +432,7 @@ class Post extends BaseObject
                        'return'          => ($a->cmd) ? bin2hex($a->cmd) : '',
                        'delivery'        => [
                                'queue_count'       => $item['delivery_queue_count'],
-                               'queue_done'        => $item['delivery_queue_done'],
+                               'queue_done'        => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
                                'notifier_pending'  => L10n::t('Notifier task is pending'),
                                'delivery_pending'  => L10n::t('Delivery to remote servers is pending'),
                                'delivery_underway' => L10n::t('Delivery to remote servers is underway'),
index 625ed5f2cb42f7c48d4277ef126b6625ec949aa4..3c12e45491813eab51952da2647e91d625937c52 100644 (file)
@@ -54,8 +54,8 @@ class APDelivery extends BaseObject
                        }
                }
 
-               if (!$success) {
-                       Worker::defer();
+               if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
+                       ItemDeliveryData::incrementQueueFailed($target_id);
                }
        }
 }
index ab3e3a6e0bdc3023bbd66833bea917bfdd6e9ef5..7733d3f575364407af538302beb90275f0a42ded 100644 (file)
@@ -327,7 +327,9 @@ class Delivery extends BaseObject
                        Model\Contact::markForArchival($contact);
 
                        Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]);
-                       Worker::defer();
+                       if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+                               Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+                       }
                }
        }
 
@@ -412,7 +414,9 @@ class Delivery extends BaseObject
                        if (empty($contact['contact-type']) || ($contact['contact-type'] != Model\Contact::TYPE_RELAY)) {
                                Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]);
                                // defer message for redelivery
-                               Worker::defer();
+                               if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+                                       Model\ItemDeliveryData::incrementQueueFailed($target_item['id'], Model\ItemDeliveryData::DIASPORA);
+                               }
                        } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
                                Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA);
                        }
index aca6cf16b3d65489adb812990f3b87a38270370f..a00d957273c88e7bdfc8d88076c0b5142b2ca053 100755 (executable)
@@ -34,7 +34,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1320);
+       define('DB_UPDATE_VERSION', 1321);
 }
 
 return [
@@ -763,6 +763,7 @@ return [
                        "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
                        "queue_count" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Initial number of delivery recipients, used as item.delivery_queue_count"],
                        "queue_done" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries, used as item.delivery_queue_done"],
+                       "queue_failed" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of unsuccessful deliveries, used as item.delivery_queue_failed"],
                        "activitypub" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via ActivityPub"],
                        "dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via DFRN"],
                        "legacy_dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via legacy DFRN"],