Пример #1
0
    def test_it_calls_closes_correctly(self, session):
        with read_only_transaction(session):
            ...

        assert session.method_calls[-2:] == [
            mock.call.commit(), mock.call.close()
        ]
Пример #2
0
    def test_it_starts_a_read_only_transaction(self, session):
        with read_only_transaction(session):
            ...

        assert session.method_calls[0] == mock.call.execute(
            "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE"
        )
Пример #3
0
def metrics_process(registry, queue):  # pragma: no cover
    session = db.get_session(registry.settings)

    newrelic.agent.initialize()
    application = newrelic.agent.application()

    while True:
        with db.read_only_transaction(session):

            newrelic.agent.record_custom_metrics(websocket_metrics(queue),
                                                 application=application)

        gevent.sleep(METRICS_INTERVAL)
Пример #4
0
def metrics_process(registry, queue):  # pragma: no cover
    session = db.get_session(registry.settings)

    newrelic.agent.initialize(
        config_file=resource_filename("h.streamer", "conf/newrelic.ini"))
    newrelic.agent.register_application(timeout=5)
    application = newrelic.agent.application()

    while True:
        with db.read_only_transaction(session):
            application.record_custom_metrics(websocket_metrics(queue))

        gevent.sleep(METRICS_INTERVAL)
Пример #5
0
def metrics_process(registry, queue):  # pragma: no cover
    session = db.get_session(registry.settings)

    with importlib_resources.as_file(NEW_RELIC_CONFIG_REF) as config_file:
        newrelic.agent.initialize(config_file=config_file)
    newrelic.agent.register_application(timeout=5)
    application = newrelic.agent.application()

    while True:
        with db.read_only_transaction(session):
            application.record_custom_metrics(websocket_metrics(queue))

        gevent.sleep(METRICS_INTERVAL)
Пример #6
0
def process_work_queue(registry, queue):
    """
    Process each message from the queue in turn, handling exceptions.

    This is the core of the streamer: we pull messages off the work queue,
    dispatching them as appropriate. The handling of each message is wrapped in
    code that ensures the database session is appropriately committed and
    closed between messages.
    """

    session = db.get_session(registry.settings)

    for msg in queue:
        with db.read_only_transaction(session):
            if isinstance(msg, messages.Message):
                messages.handle_message(msg, registry, session, TOPIC_HANDLERS)
            elif isinstance(msg, websocket.Message):
                websocket.handle_message(msg, session)
            else:
                raise UnknownMessageType(repr(msg))
Пример #7
0
    def test_it_reraises_certain_exceptions(self, session, exception):
        with pytest.raises(exception):
            with read_only_transaction(session):
                raise exception

        self._assert_rollback_and_close(session)
Пример #8
0
    def test_it_rolls_back_on_handler_exception(self, session, exception):
        with read_only_transaction(session):
            raise exception()

        self._assert_rollback_and_close(session)