예제 #1
0
def publish(message: Message) -> None:
    """
    Publishes a message on Taskhawk queue
    """
    message_body = message.as_dict()
    payload = _convert_to_json(message_body)

    if settings.IS_LAMBDA_APP:
        topic = _get_sns_topic(message.priority)
        _publish_over_sns(topic, payload, message.headers)
    else:
        queue_name = get_queue_name(message.priority)
        queue = get_queue(queue_name)
        _publish_over_sqs(queue, payload, message.headers)

    _log_published_message(message_body)
def test__convert_to_json_non_serializable(message_data):
    message_data['args'][0] = object()
    message = Message(message_data)
    with pytest.raises(TypeError):
        _convert_to_json(message.as_dict())
def test__convert_to_json_decimal(value, message_data):
    message_data['args'][0] = Decimal(value)
    message = Message(message_data)
    assert json.loads(_convert_to_json(message.as_dict()))['args'][0] == float(
        message.args[0])