Esempio n. 1
0
 def __init__(self, client_cls, endpoint, autodiscovery=True,
              autodiscovery_timeout=10, autodiscovery_interval=60,
              *args, **kwargs):
     self.client_cls = client_cls
     self.endpoint = endpoint
     self.autodiscovery = autodiscovery
     self.autodiscovery_timeout = autodiscovery_timeout
     self.args = args
     self.kwargs = kwargs
     self.cluster = Cluster(self.endpoint, self.autodiscovery_timeout)
     if self.cluster.servers:
         self.client = self.client_cls(self.cluster.servers, *self.args,
                                       **self.kwargs)
         ec_logger.info('Cluster nodes are %s', self.cluster.servers)
     else:
         self.client = None
         ec_logger.warn('Cluster nodes are empty, :(')
     self.need_update = False
     self.update_lock = Lock()
     if self.autodiscovery:
         self.timer = Timer('AutoDiscovery', autodiscovery_interval,
                            self.detect_cluster)
         self.timer.start()
     else:
         self.timer = None
Esempio n. 2
0
 def exec_func(self, *args, **kwargs):
     if self.need_update:
         ec_logger.info('Cluster nodes are: %s', self.cluster.servers)
         self.client = self.client_cls(self.cluster.servers,
                                       *self.args, **self.kwargs)
         self.need_update = False
     return client_func(*args, **kwargs)