Esempio n. 1
0
    def __init__(
        self,
        host="127.0.0.1",
        port=6379,
        password=None,
        db=0,
        cert_and_key=None,
        ca_cert=None,
        client_threads=5,
        ssl=False,
        skip_keyspace_event_setup=False,
        canceller_only=False,
        **kwargs,
    ):
        self.is_canceller_only = canceller_only
        (cert,
         key) = tuple(cert_and_key) if cert_and_key is not None else (None,
                                                                      None)
        self._sync_client = redis.StrictRedis(
            host=host,
            port=port,
            password=password,
            db=db,
            ssl_certfile=cert,
            ssl_keyfile=key,
            ssl_ca_certs=ca_cert,
            ssl=ssl,
        )

        self._shutting_down = False
        self._tasks = {}
        self._watched_keys = {}
        self._pubsub_key = slash_join(kwargs.get("orchestrator_prefix", ""),
                                      REDIS_DEFAULT_PUBSUB_KEY).lstrip("/")

        if not self.is_canceller_only:
            (self._client, self._async_executor) = wrap_with_threadpool(
                self._sync_client, client_threads)

            # Configure a subscription to watch events that the orchestrator manually publishes.
            logger.debug("creating pubsub with key %s", self._pubsub_key)
            published_pubsub = self._sync_client.pubsub()
            published_pubsub.subscribe(self._pubsub_key)
            (self._pubsub,
             self._async_executor_pub) = wrap_with_threadpool(published_pubsub)
            self._watch_published_key()

            # Configure a subscription to watch expired keyspace events.
            if not skip_keyspace_event_setup:
                self._sync_client.config_set(
                    REDIS_KEYSPACE_EVENT_CONFIG_KEY,
                    REDIS_KEYSPACE_EVENT_CONFIG_VALUE)

            expiring_pubsub = self._sync_client.pubsub()
            expiring_pubsub.psubscribe(REDIS_EXPIRED_KEYSPACE_PATTERN %
                                       (db, "*"))
            (self._pubsub_expiring,
             self._async_executor_ex) = wrap_with_threadpool(expiring_pubsub)
            self._watch_expiring_key()
Esempio n. 2
0
    def __init__(self,
                 host="127.0.0.1",
                 port=2379,
                 cert_and_key=None,
                 ca_cert=None,
                 client_threads=5,
                 canceller_only=False,
                 **kwargs):
        self.is_canceller_only = canceller_only

        logger.debug("initializing async etcd client")
        self._sync_etcd_client = etcd.Client(
            host=host,
            port=port,
            cert=tuple(cert_and_key) if cert_and_key is not None else None,
            ca_cert=ca_cert,
            protocol="http" if cert_and_key is None else "https",
            read_timeout=ETCD_READ_TIMEOUT,
        )

        if not self.is_canceller_only:
            (self._etcd_client, self._async_executor) = wrap_with_threadpool(
                self._sync_etcd_client, client_threads)

        logger.debug("creating initial orchestrator state")
        self._shutting_down = False
        self._watch_tasks = {}