]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
a little more error-checking in the queuedaemon
authorEvan Prodromou <evan@prodromou.name>
Sat, 5 Jul 2008 00:22:07 +0000 (20:22 -0400)
committerEvan Prodromou <evan@prodromou.name>
Sat, 5 Jul 2008 00:22:07 +0000 (20:22 -0400)
darcs-hash:20080705002207-84dde-c5bc4da7dbca8a32ea4126badb772e99bd4f8bf1.gz

lib/jabber.php
lib/util.php
queuedaemon.php

index 9bccc6fe4ef27cb2431b0d19ee3fde9b60b9bdf3..8f8d6a4d8c37c04ca177bd85bf1e51587e3b59c5 100644 (file)
@@ -132,10 +132,18 @@ function jabber_broadcast_notice($notice) {
                while ($sub->fetch()) {
                        $user = User::staticGet($sub->subscriber);
                        if ($user && $user->jabber && $user->jabbernotify) {
-                               jabber_send_message($user->jabber, $msg);
+                               common_log(LOG_INFO, 
+                                                  'Sending notice ' . $notice->id . ' to ' . $user->jabber,
+                                                  __FILE__);
+                               $success = jabber_send_message($user->jabber, $msg);
+                               if (!$success) {
+                                       # XXX: Not sure, but I think that's the right thing to do
+                                       return false;
+                               }
                        }
                }
        }
+       return true;
 }
 
 function jabber_format_notice(&$profile, &$notice) {
index 8beaa77d3da78e2b7c2d35580651071c9192039f..6aff62786fe68a2b9617b2dd8a4d73f84019ad52 100644 (file)
@@ -810,9 +810,9 @@ function common_redirect($url, $code=307) {
 function common_broadcast_notice($notice, $remote=false) {
        if (common_config('queue', 'enabled')) {
                # Do it later!
-               common_enqueue_notice($notice);
+               return common_enqueue_notice($notice);
        } else {
-               common_real_broadcast($notice, $remote);
+               return common_real_broadcast($notice, $remote);
        }
 }
 
@@ -827,24 +827,26 @@ function common_enqueue_notice($notice) {
        if ($result === FALSE) {
            $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
            common_log(LOG_ERROR, 'DB error inserting queue item: ' . $last_error->message);
-           return;
+           return false;
        }
        common_log(LOG_INFO, 'complete queueing notice ID = ' . $notice->id);
        return $result;
 }
          
 function common_real_broadcast($notice, $remote=false) {
-       // XXX: optionally use a queue system like http://code.google.com/p/microapps/wiki/NQDQ
+       $success = true;
        if (!$remote) {
                # Make sure we have the OMB stuff
                require_once(INSTALLDIR.'/lib/omb.php');
-               omb_broadcast_remote_subscribers($notice);
+               $success = omb_broadcast_remote_subscribers($notice);
+       }
+       if ($success) {
+               require_once(INSTALLDIR.'/lib/jabber.php');
+               $success = jabber_broadcast_notice($notice);
        }
-       require_once(INSTALLDIR.'/lib/jabber.php');
-       jabber_broadcast_notice($notice);
        // XXX: broadcast notices to SMS
        // XXX: broadcast notices to other IM
-       return true;
+       return $success;
 }
 
 function common_broadcast_profile($profile) {
index 91cfff0bfa52bcd5f6b883428fd1f65da7923b89..8da69b9da8801be5dcb6bcfd69115b88030eb4e5 100755 (executable)
@@ -96,7 +96,15 @@ do {
                if ($notice) {
                        qd_log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id);
                        # XXX: what to do if broadcast fails?
-                       common_real_broadcast($notice, qd_is_remote($notice));
+                       $result = common_real_broadcast($notice, qd_is_remote($notice));
+                       if (!$result) {
+                               qd_log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id);
+                               $orig = $qi;
+                               $qi->claimed = NULL;
+                               $qi->update($orig);
+                               qd_log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id);
+                               continue;
+                       }
                        qd_log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id);
                        $notice = NULL;
                } else {
@@ -105,7 +113,7 @@ do {
                $qi->delete();
                $qi = NULL;
        } else {
-               qd_clear_old_claims();
+               qd_clear_old_claims();
                # In busy times, sleep less
                $sleeptime = 30000000/($in_a_row+1);
                qd_log(LOG_INFO, 'sleeping ' . $sleeptime . ' microseconds');