def run(self): for raw_notification in self._consumer: message = raw_notification[1].message.value notification_data = json.loads(message) notification = construct_notification_object( self._db_repo, notification_data) if notification is None: self._consumer.commit() continue if self._keep_sending(notification.alarm_id, notification.state, notification.type, notification.period): wait_duration = notification.period - ( time.time() - notification_data['notification_timestamp']) if wait_duration > 0: time.sleep(wait_duration) notification.notification_timestamp = time.time() self._notifier.send([notification]) self._producer.publish(self._topic_name, [notification.to_json()]) self._consumer.commit()
def run(self): for raw_notification in self._consumer: message = raw_notification[1].message.value notification_data = json.loads(message) notification = construct_notification_object(self._db_repo, notification_data) if notification is None: self._consumer.commit() continue if self._keep_sending(notification.alarm_id, notification.state, notification.type, notification.period): wait_duration = notification.period - ( time.time() - notification_data['notification_timestamp']) if wait_duration > 0: time.sleep(wait_duration) notification.notification_timestamp = time.time() self._notifier.send([notification]) self._producer.publish(self._topic_name, [notification.to_json()]) self._consumer.commit()
def do_message(self, raw_notification): message = raw_notification[1].message.value notification_data = json.loads(message) notification = construct_notification_object(self._db_repo, notification_data) if notification is None: self._consumer.commit() return if self._keep_sending(notification.alarm_id, notification.state, notification.type, notification.period): wait_duration = notification.period - ( time.time() - notification_data['notification_timestamp']) if wait_duration > 0: time.sleep(wait_duration) notification.notification_timestamp = time.time() self._notifier.send([notification]) self.publish_messages([notification], self._topic_name) self._consumer.commit()
def do_message(self, raw_notification): message = raw_notification[1].message.value notification_data = json.loads(message) notification = construct_notification_object(self._db_repo, notification_data) if notification is None: self._consumer.commit() return wait_duration = self._retry_interval - ( time.time() - notification_data['notification_timestamp']) if wait_duration > 0: time.sleep(wait_duration) sent, failed = self._notifier.send([notification]) if sent: self.publish_messages([notification], self._topics['notification_topic']) if failed: notification.retry_count += 1 notification.notification_timestamp = time.time() if notification.retry_count < self._retry_max: log.error(u"retry failed for {} with name {} " u"at {}. " u"Saving for later retry.".format(notification.type, notification.name, notification.address)) self.publish_messages([notification], self._topics['retry_topic']) else: log.error(u"retry failed for {} with name {} " u"at {} after {} retries. " u"Giving up on retry." .format(notification.type, notification.name, notification.address, self._retry_max)) self._consumer.commit()
def run(self): for raw_notification in self._consumer: message = raw_notification[1].message.value message = message.decode('UTF-8') if PY3 else message notification_data = json.loads(message) notification = construct_notification_object(self._db_repo, notification_data) if notification is None: self._consumer.commit() continue wait_duration = CONF.retry_engine.interval - ( time.time() - notification_data['notification_timestamp']) if wait_duration > 0: time.sleep(wait_duration) sent, failed = self._notifier.send([notification]) if sent: self._producer.publish(CONF.kafka.notification_topic, [notification.to_json()]) if failed: notification.retry_count += 1 notification.notification_timestamp = time.time() if notification.retry_count < CONF.retry_engine.max_attempts: log.error(u"retry failed for {} with name {} " u"at {}. " u"Saving for later retry.".format(notification.type, notification.name, notification.address)) self._producer.publish(CONF.kafka.notification_retry_topic, [notification.to_json()]) else: log.error(u"retry failed for {} with name {} " u"at {} after {} retries. " u"Giving up on retry." .format(notification.type, notification.name, notification.address, CONF.retry_engine.max_attempts)) self._consumer.commit()
def run(self): for raw_notification in self._consumer: message = raw_notification[1].message.value notification_data = json.loads(message) notification = construct_notification_object( self._db_repo, notification_data) if notification is None: self._consumer.commit() continue wait_duration = CONF.retry_engine.interval - ( time.time() - notification_data['notification_timestamp']) if wait_duration > 0: time.sleep(wait_duration) sent, failed = self._notifier.send([notification]) if sent: self._producer.publish(CONF.kafka.notification_topic, [notification.to_json()]) if failed: notification.retry_count += 1 notification.notification_timestamp = time.time() if notification.retry_count < CONF.retry_engine.max_attempts: log.error(u"retry failed for {} with name {} " u"at {}. " u"Saving for later retry.".format( notification.type, notification.name, notification.address)) self._producer.publish(CONF.kafka.notification_retry_topic, [notification.to_json()]) else: log.error(u"retry failed for {} with name {} " u"at {} after {} retries. " u"Giving up on retry.".format( notification.type, notification.name, notification.address, CONF.retry_engine.max_attempts)) self._consumer.commit()