def get_client(hub=None, **kwargs):
    hub = hub or get_event_loop()
    try:
        return hub._current_http_client
    except AttributeError:
        client = hub._current_http_client = Client(hub, **kwargs)
        return client
Example #2
0
def get_client(hub=None, **kwargs):
    hub = hub or get_event_loop()
    try:
        return hub._current_http_client
    except AttributeError:
        client = hub._current_http_client = Client(hub, **kwargs)
        return client
Example #3
0
    def __init__(self, *args, **kwargs):
        if boto is None:
            raise ImportError('boto is not installed')
        super(Channel, self).__init__(*args, **kwargs)

        # SQS blows up if you try to create a new queue when one already
        # exists but with a different visibility_timeout.  This prepopulates
        # the queue_cache to protect us from recreating
        # queues that are known to already exist.
        try:
            queues = self.sqs.get_all_queues(prefix=self.queue_name_prefix)
        except exception.SQSError as exc:
            if exc.status == 403:
                raise RuntimeError(
                    'SQS authorization error, access_key={0}'.format(
                        self.sqs.access_key))
            raise
        else:
            self._queue_cache.update({
                queue.name: queue for queue in queues
            })

        # The drain_events() method stores extra messages in a local
        # Deque object. This allows multiple messages to be requested from
        # SQS at once for performance, but maintains the same external API
        # to the caller of the drain_events() method.
        self._queue_message_cache = collections.deque()

        self.hub = kwargs.get('hub') or get_event_loop()
Example #4
0
    def __init__(self, *args, **kwargs):
        if boto is None:
            raise ImportError('boto is not installed')
        super(Channel, self).__init__(*args, **kwargs)

        # SQS blows up if you try to create a new queue when one already
        # exists but with a different visibility_timeout.  This prepopulates
        # the queue_cache to protect us from recreating
        # queues that are known to already exist.
        try:
            queues = self.sqs.get_all_queues(prefix=self.queue_name_prefix)
        except exception.SQSError as exc:
            if exc.status == 403:
                raise RuntimeError(
                    'SQS authorization error, access_key={0}'.format(
                        self.sqs.access_key))
            raise
        else:
            self._queue_cache.update({queue.name: queue for queue in queues})

        # The drain_events() method stores extra messages in a local
        # Deque object. This allows multiple messages to be requested from
        # SQS at once for performance, but maintains the same external API
        # to the caller of the drain_events() method.
        self._queue_message_cache = collections.deque()

        self.hub = kwargs.get('hub') or get_event_loop()
Example #5
0
 def create(self, w):
     w.hub = get_event_loop()
     if w.hub is None:
         required_hub = getattr(w._conninfo, "requires_hub", None)
         w.hub = set_event_loop((required_hub if required_hub else _Hub)(w.timer))
     self._patch_thread_primitives(w)
     return self
Example #6
0
def get_client(hub=None, **kwargs):
    """Get or create HTTP client bound to the current event loop."""
    hub = hub or get_event_loop()
    try:
        return hub._current_http_client
    except AttributeError:
        client = hub._current_http_client = Client(hub, **kwargs)
        return client
Example #7
0
 def create(self, w):
     w.hub = get_event_loop()
     if w.hub is None:
         required_hub = getattr(w._conninfo, 'requires_hub', None)
         w.hub = set_event_loop(
             (required_hub if required_hub else _Hub)(w.timer))
     self._patch_thread_primitives(w)
     return self
def get_client(hub=None, **kwargs):
    """Get or create HTTP client bound to the current event loop."""
    hub = hub or get_event_loop()
    try:
        return hub._current_http_client
    except AttributeError:
        client = hub._current_http_client = Client(hub, **kwargs)
        return client
Example #9
0
def hub(request):
    from kombu.async import Hub, get_event_loop, set_event_loop
    _prev_hub = get_event_loop()
    hub = Hub()
    set_event_loop(hub)

    yield hub

    if _prev_hub is not None:
        set_event_loop(_prev_hub)
Example #10
0
def hub(request):
    from kombu. async import Hub, get_event_loop, set_event_loop
    _prev_hub = get_event_loop()
    hub = Hub()
    set_event_loop(hub)

    yield hub

    if _prev_hub is not None:
        set_event_loop(_prev_hub)
Example #11
0
def hub(request):
    from kombu.async import Hub, get_event_loop, set_event_loop
    _prev_hub = get_event_loop()
    hub = Hub()
    set_event_loop(hub)

    def fin():
        if _prev_hub is not None:
            set_event_loop(_prev_hub)
    request.addfinalizer(fin)
    return hub
Example #12
0
    def __init__(self, *args, **kwargs):
        if boto3 is None:
            raise ImportError('boto3 is not installed')
        super(Channel, self).__init__(*args, **kwargs)

        # SQS blows up if you try to create a new queue when one already
        # exists but with a different visibility_timeout.  This prepopulates
        # the queue_cache to protect us from recreating
        # queues that are known to already exist.
        self._update_queue_cache(self.queue_name_prefix)

        self.hub = kwargs.get('hub') or get_event_loop()
Example #13
0
    def __init__(self, *args, **kwargs):
        if boto3 is None:
            raise ImportError('boto3 is not installed')
        super(Channel, self).__init__(*args, **kwargs)

        # SQS blows up if you try to create a new queue when one already
        # exists but with a different visibility_timeout.  This prepopulates
        # the queue_cache to protect us from recreating
        # queues that are known to already exist.
        self._update_queue_cache(self.queue_name_prefix)

        self.hub = kwargs.get('hub') or get_event_loop()
Example #14
0
def hub(request):
    from kombu. async import Hub, get_event_loop, set_event_loop
    _prev_hub = get_event_loop()
    hub = Hub()
    set_event_loop(hub)

    def fin():
        if _prev_hub is not None:
            set_event_loop(_prev_hub)

    request.addfinalizer(fin)
    return hub
Example #15
0
    def __init__(self, *args, **kwargs):
        if boto is None:
            raise ImportError('boto is not installed')
        super(Channel, self).__init__(*args, **kwargs)

        # SQS blows up if you try to create a new queue when one already
        # exists but with a different visibility_timeout.  This prepopulates
        # the queue_cache to protect us from recreating
        # queues that are known to already exist.
        self._update_queue_cache(self.queue_name_prefix)

        # The drain_events() method stores extra messages in a local
        # Deque object.  This allows multiple messages to be requested from
        # SQS at once for performance, but maintains the same external API
        # to the caller of the drain_events() method.
        self._queue_message_cache = collections.deque()

        self.hub = kwargs.get('hub') or get_event_loop()
Example #16
0
    def __init__(self, *args, **kwargs):
        if boto is None:
            raise ImportError('boto is not installed')
        super(Channel, self).__init__(*args, **kwargs)

        # SQS blows up if you try to create a new queue when one already
        # exists but with a different visibility_timeout.  This prepopulates
        # the queue_cache to protect us from recreating
        # queues that are known to already exist.
        self._update_queue_cache(self.queue_name_prefix)

        # The drain_events() method stores extra messages in a local
        # Deque object. This allows multiple messages to be requested from
        # SQS at once for performance, but maintains the same external API
        # to the caller of the drain_events() method.
        self._queue_message_cache = collections.deque()

        self.hub = kwargs.get('hub') or get_event_loop()
Example #17
0
 def create(self, w):
     w.hub = get_event_loop()
     if w.hub is None:
         w.hub = set_event_loop(_Hub(w.timer))
     self._patch_thread_primitives(w)
     return self
Example #18
0
 def setUp(self):
     from kombu.async import Hub, get_event_loop, set_event_loop
     self._prev_hub = get_event_loop()
     self.hub = Hub()
     set_event_loop(self.hub)
     super(HubCase, self).setUp()
Example #19
0
 def setUp(self):
     from kombu. async import Hub, get_event_loop, set_event_loop
     self._prev_hub = get_event_loop()
     self.hub = Hub()
     set_event_loop(self.hub)
     super(HubCase, self).setUp()
Example #20
0
 def create(self, w):
     w.hub = get_event_loop()
     if w.hub is None:
         w.hub = set_event_loop(_Hub(w.timer))
     self._patch_thread_primitives(w)
     return self