def run(self): log.info("Starting MobileStreamingUpdateProcessor connecting to uri: " + self._uri) self._running = True while self._running: try: init_start = time.time() messages = self._connect() for msg in messages: if not self._running: break message_ok = self.process_message(self._store, self._requester, msg) if message_ok is True and self._ready.is_set() is False: log.info("MobileStreamingUpdateProcessor initialized ok.") init_duration = int((time.time() - init_start) * 1000) request_success.fire(request_type="ld:init", name="mobile", response_time=init_duration, response_length=0) self._ready.set() except UnsuccessfulResponseException as e: log.error(http_error_message(e.status, "stream connection")) init_duration = int((time.time() - init_start) * 1000) request_failure.fire(request_type="ld:init", name="mobile", response_time=init_duration, response_length=0, exception=e) if not is_http_error_recoverable(e.status): self._ready.set() # if client is initializing, make it stop waiting; has no effect if already inited self.stop() break except Exception as e: init_duration = int((time.time() - init_start) * 1000) request_failure.fire(request_type="ld:init", name="mobile", response_time=init_duration, response_length=0, exception=e) log.warning("Caught exception. Restarting stream connection after one second. %s" % e) # no stacktrace here because, for a typical connection error, it'll just be a lengthy tour of urllib3 internals time.sleep(1)
def run(self): if not self._running: log.info("Starting PollingUpdateProcessor with request interval: " + str(self._config.poll_interval)) self._running = True while self._running: start_time = time.time() try: all_data = self._requester.get_all_data() self._store.init(all_data) if not self._ready.is_set() is True and self._store.initialized is True: log.info("PollingUpdateProcessor initialized ok") self._ready.set() except UnsuccessfulResponseException as e: log.error(http_error_message(e.status, "polling request")) if not is_http_error_recoverable(e.status): self._ready.set() # if client is initializing, make it stop waiting; has no effect if already inited self.stop() break except Exception as e: log.exception( 'Error: Exception encountered when updating flags. %s' % e) elapsed = time.time() - start_time if elapsed < self._config.poll_interval: time.sleep(self._config.poll_interval - elapsed)
def _handle_response(self, r): server_date_str = r.getheader('Date') if server_date_str is not None: server_date = parsedate(server_date_str) if server_date is not None: timestamp = int(time.mktime(server_date) * 1000) self._last_known_past_time = timestamp if r.status > 299: log.error(http_error_message(r.status, "event delivery", "some events were dropped")) if not is_http_error_recoverable(r.status): self._disabled = True return
def run(self): log.info("Starting StreamingUpdateProcessor connecting to uri: " + self._uri) self._running = True attempts = 0 while self._running: if attempts > 0: delay = self._retry_delay.next_retry_delay(time.time()) log.info("Will reconnect after delay of %fs" % delay) time.sleep(delay) attempts += 1 try: self._es_started = int(time.time() * 1000) messages = self._connect() for msg in messages: if not self._running: break self._retry_delay.set_good_since(time.time()) message_ok = self.process_message(self._store, msg) if message_ok: self._record_stream_init(False) self._es_started = None if message_ok is True and self._ready.is_set() is False: log.info("StreamingUpdateProcessor initialized ok.") self._ready.set() except UnsuccessfulResponseException as e: log.error(http_error_message(e.status, "stream connection")) self._record_stream_init(True) self._es_started = None if not is_http_error_recoverable(e.status): self._ready.set( ) # if client is initializing, make it stop waiting; has no effect if already inited self.stop() break except Exception as e: log.warning( "Unexpected error on stream connection: %s, will retry" % e) self._record_stream_init(True) self._es_started = None
def run(self): log.info("Starting StreamingUpdateProcessor connecting to uri: " + self._uri) self._running = True while self._running: try: messages = self._connect() for msg in messages: if not self._running: break message_ok = self.process_message(self._store, self._requester, msg) if message_ok is True and self._ready.is_set() is False: log.info("StreamingUpdateProcessor initialized ok.") self._ready.set() except UnsuccessfulResponseException as e: log.error(http_error_message(e.status, "stream connection")) if not is_http_error_recoverable(e.status): self._ready.set() # if client is initializing, make it stop waiting; has no effect if already inited self.stop() break except Exception as e: log.warning("Caught exception. Restarting stream connection after one second. %s" % e) # no stacktrace here because, for a typical connection error, it'll just be a lengthy tour of urllib3 internals time.sleep(1)
def run(self): log.info("Starting StreamingUpdateProcessor connecting to uri: " + self._uri) self._running = True while self._running: try: self._es_started = int(time.time() * 1000) messages = self._connect() for msg in messages: if not self._running: break message_ok = self.process_message(self._store, self._requester, msg) if message_ok: self._record_stream_init(False) self._es_started = None if message_ok is True and self._ready.is_set() is False: log.info("StreamingUpdateProcessor initialized ok.") self._ready.set() except UnsuccessfulResponseException as e: log.error(http_error_message(e.status, "stream connection")) self._record_stream_init(True) self._es_started = None if not is_http_error_recoverable(e.status): self._ready.set( ) # if client is initializing, make it stop waiting; has no effect if already inited self.stop() break except Exception as e: log.warning( "Caught exception. Restarting stream connection after one second. %s" % e) self._record_stream_init(True) self._es_started = None # no stacktrace here because, for a typical connection error, it'll just be a lengthy tour of urllib3 internals time.sleep(1)
def run(self): if not self._running: log.info("Starting PollingUpdateProcessor with request interval: " + str(self._config.poll_interval)) self._running = True while self._running: start_time = time.time() try: all_data = self._requester.get_all_data() self._store.init(all_data) if not self._ready.is_set() is True and self._store.initialized is True: log.info("PollingUpdateProcessor initialized ok") self._ready.set() except UnsuccessfulResponseException as e: log.error(http_error_message(e.status, "polling request")) if not is_http_error_recoverable(e.status): self._ready.set() # if client is initializing, make it stop waiting; has no effect if already inited self.stop() except Exception as e: log.exception( 'Error: Exception encountered when updating flags. %s' % e) elapsed = time.time() - start_time if elapsed < self._config.poll_interval: time.sleep(self._config.poll_interval - elapsed)