From eb98c14af6f1a7cc185d925c9120e5d1c93329f6 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 12 Feb 2013 13:59:28 -0500 Subject: [PATCH] api: Make call_on_each_message restart if 'last' is too old. This should fix the symptoms of the problem we've been having where a few API clients using the MIT Zephyr mirroring system sometimes seem to end up with a too-old value of last. (imported from commit 9f2426fa6a7e8365e8d3443bfd2cce3238cc9510) --- humbug/__init__.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/humbug/__init__.py b/humbug/__init__.py index 027527c..7ccc375 100644 --- a/humbug/__init__.py +++ b/humbug/__init__.py @@ -195,15 +195,28 @@ class Client(object): while True: if max_message_id is not None: options["last"] = str(max_message_id) + elif options.get('last') is not None: + options.pop('last') res = self.get_messages(options) if 'error' in res.get('result'): - if self.verbose: - if res["result"] == "http-error": + if res["result"] == "http-error": + if self.verbose: print "HTTP error fetching messages -- probably a server restart" - elif res["result"] == "connection-error": + elif res["result"] == "connection-error": + if self.verbose: print "Connection error fetching messages -- probably server is temporarily down?" - else: + else: + if self.verbose: print "Server returned error:\n%s" % res["msg"] + if res["msg"].startswith("last value of") and \ + "too old! Minimum valid is" in res["msg"]: + # We may have missed some messages while the + # network was down or something, but there's + # not really anything we can do about it other + # than resuming getting new ones. + # + # Reset max_message_id to just subscribe to new messages + max_message_id = None # TODO: Make this back off once it's more reliable time.sleep(1) continue