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)
This commit is contained in:
		
							parent
							
								
									e7f46e0823
								
							
						
					
					
						commit
						eb98c14af6
					
				
					 1 changed files with 17 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue