def run(self): while True: eventlet.sleep(0) try: for data in self.pub_sub.listen(): if 'subscribe' == data['type']: continue if 'unsubscribe' == data['type']: continue if 'message' == data['type']: entry = pub_sub_api.unpack_message(data['data']) entry_json = jsonutils.loads(entry) self.db_changes_callback(entry_json['table'], entry_json['key'], entry_json['action'], entry_json['value'], entry_json['topic']) except Exception as e: LOG.warning(e) try: connection = self.pub_sub.connection connection.connect() self.db_changes_callback(None, None, 'sync', None, None) except Exception as e: LOG.exception( _LE("reconnect error %(ip)s:%(port)s") % { 'ip': self.ip, 'port': self.plugin_updates_port })
def run(self): while True: eventlet.sleep(0) try: for data in self.pub_sub.listen(): if 'subscribe' == data['type']: continue if 'unsubscribe' == data['type']: continue if 'message' == data['type']: entry = pub_sub_api.unpack_message(data['data']) entry_json = jsonutils.loads(entry) self.db_changes_callback( entry_json['table'], entry_json['key'], entry_json['action'], entry_json['value'], entry_json['topic']) except Exception as e: LOG.warning(e) try: connection = self.pub_sub.connection connection.connect() self.db_changes_callback(None, None, 'sync', None, None) except Exception as e: LOG.exception(_LE("reconnect error %(ip)s:%(port)s") % {'ip': self.ip, 'port': self.plugin_updates_port})
def handle_event(self, event): unpacked_event = pub_sub_api.unpack_message(event["kv"]["value"]) self.db_changes_callback( unpacked_event['table'], unpacked_event['key'], unpacked_event['action'], unpacked_event['value'], unpacked_event['topic'], )
def run(self): self.sub_socket = self.connect() LOG.info( _LI("Starting Subscriber on ports %(endpoints)s ") % {'endpoints': str(self.uri_list)}) while True: try: eventlet.sleep(0) [topic, data] = self.sub_socket.recv_multipart() message = pub_sub_api.unpack_message(data) self.db_changes_callback( message['table'], message['key'], message['action'], message['value'], message['topic'], ) except Exception as e: LOG.warning(e) self.sub_socket.close() self.sub_socket = self.connect() self.db_changes_callback(None, None, 'sync', None, None)
def run(self): self.sub_socket = self.connect() LOG.info(_LI("Starting Subscriber on ports %(endpoints)s ") % {'endpoints': str(self.uri_list)}) while True: try: eventlet.sleep(0) [topic, data] = self.sub_socket.recv_multipart() entry_json = pub_sub_api.unpack_message(data) message = jsonutils.loads(entry_json) self.db_changes_callback( message['table'], message['key'], message['action'], message['value'], message['topic'], ) except Exception as e: LOG.warning(e) self.sub_socket.close() self.sub_socket = self.connect() self.db_changes_callback(None, None, 'sync', None, None)
def run(self): while not self.is_closed: time.sleep(0) try: if self.pub_sub is not None: for data in self.pub_sub.listen(): if 'subscribe' == data['type']: continue elif 'unsubscribe' == data['type']: continue elif 'message' == data['type']: # Redis management module publishes node list # on topic 'redis'. # All other topics are for the user. if data['channel'] == 'redis': # redis ha message message = pub_sub_api.unpack_message( data['data']) value = jsonutils.loads(message['value']) self.redis_mgt.redis_failover_callback(value) else: self._handle_incoming_event(data['data']) else: LOG.warning( "receive unknown message in " "subscriber %(type)s", {'type': data['type']}) else: LOG.warning("pubsub lost connection %(ip)s:" "%(port)s", { 'ip': self.ip, 'port': self.plugin_updates_port }) time.sleep(1) except Exception as e: LOG.warning( "subscriber listening task lost " "connection " "%(e)s", {'e': e}) try: connection = self.pub_sub.connection connection.connect() self.pub_sub.on_connect(connection) # self.db_changes_callback(None, None, 'sync', None, None) # notify restart self.db_changes_callback(None, None, constants.CONTROLLER_DBRESTART, False, None) except Exception: self.redis_mgt.remove_node_from_master_list(self.remote) self._update_client() # if pubsub not none notify restart if self.remote is not None: # to re-subscribe self.register_hamsg_for_db() self.db_changes_callback( None, None, constants.CONTROLLER_DBRESTART, True, None) else: LOG.warning("there is no more db node available") LOG.exception("reconnect error %(ip)s:%(port)s", { 'ip': self.ip, 'port': self.plugin_updates_port })
def run(self): while True: eventlet.sleep(0) try: if self.pub_sub is not None: for data in self.pub_sub.listen(): if 'subscribe' == data['type']: continue elif 'unsubscribe' == data['type']: continue elif 'message' == data['type']: message = pub_sub_api.unpack_message(data['data']) if message['table'] != 'ha': self.db_changes_callback( message['table'], message['key'], message['action'], message['value'], message['topic']) else: # redis ha message value = jsonutils.loads(message['value']) self.redis_mgt.redis_failover_callback( value) else: LOG.warning(_LW("receive unknown message in " "subscriber %(type)s"), {'type': data['type']}) else: LOG.warning(_LW("pubsub lost connection %(ip)s:" "%(port)s"), {'ip': self.ip, 'port': self.plugin_updates_port}) eventlet.sleep(1) except Exception as e: LOG.warning(_LW("subscriber listening task lost " "connection " "%(e)s"), {'e': e}) try: connection = self.pub_sub.connection connection.connect() self.pub_sub.on_connect(connection) # self.db_changes_callback(None, None, 'sync', None, None) # notify restart self.db_changes_callback(None, None, 'dbrestart', False, None) except Exception: self.redis_mgt.remove_node_from_master_list(self.remote) self._update_client() # if pubsub not none notify restart if self.remote is not None: # to re-subscribe self.register_hamsg_for_db() self.db_changes_callback(None, None, 'dbrestart', True, None) else: LOG.warning(_LW("there is no more db node " "available")) LOG.exception(_LE("reconnect error %(ip)s:%(port)s"), {'ip': self.ip, 'port': self.plugin_updates_port})