Пример #1
0
    def test_it_adds_timeout_options_for_failfast(self, Connection):
        realtime.get_connection({}, fail_fast=True)

        Connection.assert_called_once_with(
            Any.string(),
            transport_options={
                "max_retries": Any.int(),
                "interval_start": Any(),
                "interval_step": Any(),
                "interval_max": Any(),
            },
        )
Пример #2
0
def process_messages(settings, routing_key, work_queue, raise_error=True):
    """
    Configure, start, and monitor a realtime consumer for the specified
    routing key.

    This sets up a :py:class:`h.realtime.Consumer` to route messages from
    `routing_key` to the passed `work_queue`, and starts it. The consumer
    should never return. If it does, this function will raise an exception.
    """
    def _handler(payload):
        try:
            message = Message(topic=routing_key, payload=payload)
            work_queue.put(message, timeout=0.1)
        except Full:
            log.warn('Streamer work queue full! Unable to queue message from '
                     'h.realtime having waited 0.1s: giving up.')

    conn = realtime.get_connection(settings)
    sentry_client = h.sentry.get_client(settings)
    statsd_client = h.stats.get_client(settings)
    consumer = Consumer(connection=conn,
                        routing_key=routing_key,
                        handler=_handler,
                        sentry_client=sentry_client,
                        statsd_client=statsd_client)
    consumer.run()

    if raise_error:
        raise RuntimeError('Realtime consumer quit unexpectedly!')
Пример #3
0
def process_messages(settings, routing_key, work_queue, raise_error=True):
    """
    Configure, start, and monitor a realtime consumer for the specified
    routing key.

    This sets up a :py:class:`h.realtime.Consumer` to route messages from
    `routing_key` to the passed `work_queue`, and starts it. The consumer
    should never return. If it does, this function will raise an exception.
    """

    def _handler(payload):
        try:
            message = Message(topic=routing_key, payload=payload)
            work_queue.put(message, timeout=0.1)
        except Full:
            log.warn('Streamer work queue full! Unable to queue message from '
                     'h.realtime having waited 0.1s: giving up.')

    conn = realtime.get_connection(settings)
    sentry_client = h.sentry.get_client(settings)
    consumer = Consumer(connection=conn,
                        routing_key=routing_key,
                        handler=_handler, sentry_client=sentry_client)
    consumer.run()

    if raise_error:
        raise RuntimeError('Realtime consumer quit unexpectedly!')
Пример #4
0
 def test_allows_to_overwrite_broker_url(self, Connection):
     broker_url = "amqp://*****:*****@rabbitmq.int:5673/prj"
     realtime.get_connection({"broker_url": broker_url})
     Connection.assert_called_once_with(broker_url)
Пример #5
0
 def test_returns_the_connection(self, Connection):
     connection = realtime.get_connection({})
     assert connection == Connection.return_value
Пример #6
0
 def test_defaults(self, Connection):
     realtime.get_connection({})
     Connection.assert_called_once_with(
         "amqp://*****:*****@localhost:5672//")
Пример #7
0
 def test_allows_to_overwrite_broker_url(self, Connection):
     broker_url = 'amqp://*****:*****@rabbitmq.int:5673/prj'
     realtime.get_connection({'broker_url': broker_url})
     Connection.assert_called_once_with(broker_url)
Пример #8
0
 def test_returns_the_connection(self, Connection):
     connection = realtime.get_connection({})
     assert connection == Connection.return_value
Пример #9
0
 def test_defaults(self, Connection):
     realtime.get_connection({})
     Connection.assert_called_once_with('amqp://*****:*****@localhost:5672//')
Пример #10
0
    def test_it_adds_timeout_options_for_failfast(self, Connection):
        realtime.get_connection({}, fail_fast=True)

        Connection.assert_called_once_with(
            Any.string(), transport_options=RETRY_POLICY_QUICK)