Don't accept non-objects before testing with "instanceof".
[quix0rs-gnu-social.git] / plugins / OStatus / lib / huboutqueuehandler.php
index 0791c7e5db16c4fd186ba5158bddc93546172770..46d9e08e3924922b4b9da6499f24d79c529e47d2 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
 /**
  * Send a raw PuSH atom update from our internal hub.
  * @package Hub
@@ -33,20 +37,29 @@ class HubOutQueueHandler extends QueueHandler
     {
         $sub = $data['sub'];
         $atom = $data['atom'];
+        $retries = $data['retries'];
 
+        assert(is_object($sub));
         assert($sub instanceof HubSub);
         assert(is_string($atom));
 
         try {
             $sub->push($atom);
         } catch (Exception $e) {
-            common_log(LOG_ERR, "Failed PuSH to $sub->callback for $sub->topic: " .
-                                $e->getMessage());
-            // @fixme Reschedule a later delivery?
-            return true;
+            $retries--;
+            $msg = "Failed PuSH to $sub->callback for $sub->topic: " .
+                   $e->getMessage();
+            if ($retries > 0) {
+                common_log(LOG_INFO, "$msg; scheduling for $retries more tries");
+
+                // @fixme when we have infrastructure to schedule a retry
+                // after a delay, use it.
+                $sub->distribute($atom, $retries);
+            } else {
+                common_log(LOG_ERR, "$msg; discarding");
+            }
         }
 
         return true;
     }
 }
-