]> git.mxchange.org Git - friendica.git/commitdiff
Introducing the "failed" counter
authorMichael <heluecht@pirati.ca>
Thu, 12 May 2022 06:54:58 +0000 (06:54 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 12 May 2022 06:54:58 +0000 (06:54 +0000)
database.sql
doc/database/db_post-delivery.md
src/Model/Post/Delivery.php
src/Worker/APDelivery.php
static/dbstructure.config.php

index 1d632eb3fbfc6e0d9e907ab495b416fc95b90a1b..1508f358dc071046bf01410dcea8da338a395c4b 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.05-rc (Siberian Iris)
--- DB_UPDATE_VERSION 1461
+-- DB_UPDATE_VERSION 1462
 -- ------------------------------------------
 
 
@@ -1126,6 +1126,7 @@ CREATE TABLE IF NOT EXISTS `post-delivery` (
        `uid` mediumint unsigned COMMENT 'Delivering user',
        `created` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
        `command` varbinary(32) COMMENT '',
+       `failed` tinyint DEFAULT 0 COMMENT 'Number of times the delivery has failed',
         PRIMARY KEY(`uri-id`,`inbox-id`),
         INDEX `inbox-id_created` (`inbox-id`,`created`),
         INDEX `uid` (`uid`),
index 79e858193a8b26e185c8f28a72a39fcab23bcb72..8b149b57159fed955ca90f50a637e5d6b0dbc0c1 100644 (file)
@@ -13,6 +13,7 @@ Fields
 | uid      | Delivering user                                           | mediumint unsigned | YES  |     | NULL                |       |
 | created  |                                                           | datetime           | YES  |     | 0001-01-01 00:00:00 |       |
 | command  |                                                           | varbinary(32)      | YES  |     | NULL                |       |
+| failed   | Number of times the delivery has failed                   | tinyint            | YES  |     | 0                   |       |
 
 Indexes
 ------------
index 8cd01c3a855c66c457d8e6051510f40ca177fb34..9ccfdc15a6bdd24888c9d756f38a0216db8cf8fd 100644 (file)
@@ -57,8 +57,19 @@ class Delivery
                DBA::delete('post-delivery', ['uri-id' => $uri_id, 'inbox-id' => ItemURI::getIdByURI($inbox)]);
        }
 
+       /**
+        * Increment "failed" counter for the given inbox and post
+        *
+        * @param integer $uri_id
+        * @param string  $inbox
+        */
+       public static function incrementFailed(int $uri_id, string $inbox)
+       {
+               return DBA::e('UPDATE `post-delivery` SET `failed` = `failed` + 1 WHERE `uri-id` = ? AND `inbox-id` = ?', $uri_id, ItemURI::getIdByURI($inbox));
+       }
+
        public static function selectForInbox(string $inbox)
        {
-               return DBA::selectToArray('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]);
+               return DBA::selectToArray('post-delivery', [], ["`inbox-id` = ? AND `failed` < ?", ItemURI::getIdByURI($inbox), 15], ['order' => ['created']]);
        }
 }
index 83e47172fc09ae86078c59e744a817cc9a314b6c..4091a89bc7bb68a310a07da714ada9eed40857d4 100644 (file)
@@ -131,8 +131,12 @@ class APDelivery
                        $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
                        if (!empty($data)) {
                                $success = HTTPSignature::transmit($data, $inbox, $uid);
-                               if ($success && $uri_id) {
-                                       Post\Delivery::remove($uri_id, $inbox);
+                               if ($uri_id) {
+                                       if ($success) {
+                                               Post\Delivery::remove($uri_id, $inbox);
+                                       } else {
+                                               Post\Delivery::incrementFailed($uri_id, $inbox);
+                                       }
                                }
                        }
                }
index 08634290b7dd854aae48b5d1e3f32db8cb1c9aa3..101e3da343a407d06b3ed29fd92e6b3cd5425484 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1461);
+       define('DB_UPDATE_VERSION', 1462);
 }
 
 return [
@@ -1165,6 +1165,7 @@ return [
                        "uid" => ["type" => "mediumint unsigned", "foreign" => ["user" => "uid"], "comment" => "Delivering user"],
                        "created" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
                        "command" => ["type" => "varbinary(32)", "comment" => ""],
+                       "failed" => ["type" => "tinyint", "default" => 0, "comment" => "Number of times the delivery has failed"],
                ],
                "indexes" => [
                        "PRIMARY" => ["uri-id", "inbox-id"],