Example #1
0
def test_on_future_errors():
    manager = LoaferManager(routes=[])
    manager.runner = mock.Mock()
    future = asyncio.Future()
    future.set_exception(ProviderError)
    manager.on_future__errors(future)

    assert manager.runner.prepare_stop.called
    manager.runner.prepare_stop.assert_called_once_with()
Example #2
0
def test_on_future_errors_cancelled():
    manager = LoaferManager(routes=[])
    manager.runner = mock.Mock()
    future = asyncio.Future()
    future.cancel()
    manager.on_future__errors(future)

    assert manager.runner.prepare_stop.called
    manager.runner.prepare_stop.assert_called_once_with()
Example #3
0
def test_on_loop__stop():
    manager = LoaferManager(routes=[])
    manager.dispatcher = mock.Mock()
    manager._future = mock.Mock()
    manager.on_loop__stop()

    assert manager.dispatcher.stop.called
    assert manager._future.cancel.called
Example #4
0
def test_default_runner():
    manager = LoaferManager(routes=[])
    assert manager.runner
    assert isinstance(manager.runner, LoaferRunner)
Example #5
0
def test_custom_runner():
    runner = mock.Mock()
    manager = LoaferManager(routes=[], runner=runner)
    assert manager.runner
    assert isinstance(manager.runner, mock.Mock)
Example #6
0
def test_dispatcher_invalid_route_instance():
    manager = LoaferManager(routes=[mock.Mock()])
    with pytest.raises(ConfigurationError):
        manager.dispatcher
Example #7
0
def test_dispatcher(dummy_route):
    manager = LoaferManager(routes=[dummy_route])
    assert manager.dispatcher
    assert isinstance(manager.dispatcher, LoaferDispatcher)
Example #8
0
def test_dispatcher_invalid_routes():
    manager = LoaferManager(routes=[])
    with pytest.raises(ConfigurationError):
        manager.dispatcher
Example #9
0
def test_dispatcher_without_enabled_routes(dummy_route):
    dummy_route.enabled = False
    manager = LoaferManager(routes=[dummy_route])
    with pytest.raises(ConfigurationError):
        manager.dispatcher
Example #10
0
from loafer.managers import LoaferManager

from .routes import routes

service = LoaferManager(routes=routes)
print('iniciando serviço ...')
service.run()
Example #11
0
from loafer.managers import LoaferManager

from .routes import routes

manager = LoaferManager(routes=routes)
manager.run()
Example #12
0
import os

from loafer.ext.aws.routes import SNSQueueRoute
from loafer.managers import LoaferManager


async def echo_message_handler(message, *args):
    print(f"message is {message}")
    print(f"args is {args}")

    await asyncio.sleep(0.5)
    return True


async def error_handler(exc_type, message):
    print(f"exception {exc_type} received")
    return False


endpoint_url = os.environ.get("AWS_ENDPOINT_URL", "http://localhost:4100")

routes = (SNSQueueRoute(
    "echo__loafer__notification",
    provider_options={"endpoint_url": endpoint_url},
    handler=echo_message_handler,
    error_handler=error_handler,
), )

manager = LoaferManager(routes=routes)
manager.run(debug=True)