]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Retry using the waiting queue so as to preserve message ordering
authorLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Wed, 11 Aug 2010 02:23:45 +0000 (19:23 -0700)
committerLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Wed, 11 Aug 2010 02:23:45 +0000 (19:23 -0700)
plugins/Irc/IrcPlugin.php
plugins/Irc/Irc_waiting_message.php
plugins/Irc/ircmanager.php

index 54b7585211e288944b2d9afb0f60f08489b92600..e073d6f13dd94a74965133b9768edf6f6a531a6c 100644 (file)
@@ -164,6 +164,7 @@ class IrcPlugin extends ImPlugin {
                                                  false, 'PRI', null, null, true),
                                    new ColumnDef('data', 'blob', null, false),
                                    new ColumnDef('prioritise', 'tinyint', 1, false),
+                                   new ColumnDef('attempts', 'integer', null, false),
                                    new ColumnDef('created', 'datetime', null, false),
                                    new ColumnDef('claimed', 'datetime')));
 
index 05f72754c76ffff87295fecb6c29316b7da21569..59eec63d8d697e8ad4855cd3108140493fe581df 100644 (file)
@@ -10,6 +10,7 @@ class Irc_waiting_message extends Memcached_DataObject {
     public $id;                              // int primary_key not_null auto_increment\r
     public $data;                            // blob not_null\r
     public $prioritise;                      // tinyint(1) not_null\r
+    public $attempts;                        // int not_null\r
     public $created;                         // datetime() not_null\r
     public $claimed;                         // datetime()\r
 \r
@@ -111,6 +112,22 @@ class Irc_waiting_message extends Memcached_DataObject {
         return null;\r
     }\r
 \r
+    /**\r
+    * Increment the attempts count\r
+    *\r
+    * @return void\r
+    * @throws Exception\r
+    */\r
+    public function incAttempts() {\r
+        $orig = clone($this);\r
+        $this->attempts++;\r
+        $result = $this->update($orig);\r
+\r
+        if (!$result) {\r
+            throw Exception(sprintf(_m("Could not increment attempts count for %d"), $this->id));\r
+        }\r
+    }\r
+\r
     /**\r
      * Release a claimed item.\r
      */\r
index aa0ff3539f9c27fa393a8b5d841eedb419136a08..5f55e6b34dd7a7310c27014a69ee22148342a766 100644 (file)
@@ -101,19 +101,21 @@ class IrcManager extends ImManager {
                     $this->messageWaiting = false;
                     return;
                 }
-                $data = unserialize($wm->data);
 
-                if (!$this->send_raw_message($data)) {
-                    $this->plugin->enqueue_outgoing_raw(
-                        array(
-                            'type' => 'message',
-                            'prioritise' => $data['prioritise'],
-                            'data' => $data['data']
-                        )
-                    );
+                $data = unserialize($wm->data);
+                $wm->incAttempts();
+
+                if ($this->send_raw_message($data)) {
+                    $wm->delete();
+                } else {
+                    if ($wm->attempts <= common_config('queue', 'max_retries')) {
+                        // Try again next idle
+                        $wm->releaseClaim();
+                    } else {
+                        // Exceeded the maximum number of retries
+                        $wm->delete();
+                    }
                 }
-
-                $wm->delete();
             }
         }
     }
@@ -276,6 +278,7 @@ class IrcManager extends ImManager {
 
         $wm->data       = serialize($data);
         $wm->prioritise = $data['prioritise'];
+        $wm->attempts   = 0;
         $wm->created    = common_sql_now();
         $result         = $wm->insert();