def set_connection(): client = client_mod.Client(admin=True) instance = client.instance(INSTANCE_ID, LOCATION_ID) operation = instance.create() if not _wait_until_complete(operation): raise RuntimeError('Instance creation exceed 5 seconds.') Config.CONNECTION = Connection(instance=instance)
def set_connection(): client = client_mod.Client(admin=True) instance = client.instance(INSTANCE_ID, labels=LABELS) cluster = instance.cluster( CLUSTER_ID, location_id=LOCATION_ID, serve_nodes=SERVER_NODES ) operation = instance.create(clusters=[cluster]) operation.result(10) Config.CONNECTION = Connection(instance=instance)
def __init__(self, size, **kwargs): if not isinstance(size, six.integer_types): raise TypeError("Pool size arg must be an integer") if size < _MIN_POOL_SIZE: raise ValueError("Pool size must be positive") self._lock = threading.Lock() self._queue = six.moves.queue.LifoQueue(maxsize=size) self._thread_connections = threading.local() connection_kwargs = kwargs connection_kwargs["autoconnect"] = False if "instance" not in connection_kwargs: connection_kwargs["instance"] = _get_instance() for _ in six.moves.range(size): connection = Connection(**connection_kwargs) self._queue.put(connection)