def _send_task_to_dlx(message, message_ttl, routing_key='workflow'):
    """
    We use Rabbit's `Dead Letter Exchange` to achieve execution scheduling:
    1. Create a Dead Letter Exchange with the following parameters:
        - `ttl` (time until message is moved to another queue): the delta
            between now and the scheduled time.
        - `dead-letter-exchange`: The temporary exchange that is used to
            forward the task
        - `dead-letter-routing-key`: The queue we want the task to be
             ultimately sent to (in this case MGMTWORKER queue).
    2. Send the execution to that DLX
    3. When ttl is passed the task will automatically be sent to the
        MGMTWORKER queue and will be executed normally.
    """
    dlx_exchange = message['dlx_id']
    dlx_routing_key = message['dlx_id'] + '_queue'

    client = _get_amqp_client()
    send_handler = ScheduledExecutionHandler(exchange=dlx_exchange,
                                             exchange_type='direct',
                                             routing_key=dlx_routing_key,
                                             target_exchange=MGMTWORKER_QUEUE,
                                             target_routing_key=routing_key,
                                             ttl=message_ttl)
    client.add_handler(send_handler)
    with client:
        send_handler.publish(message)
def _send_task_to_dlx(message, message_ttl, routing_key='workflow'):
    """
    We use Rabbit's `Dead Letter Exchange` to achieve execution scheduling:
    1. Create a Dead Letter Exchange with the following parameters:
        - `ttl` (time until message is moved to another queue): the delta
            between now and the scheduled time.
        - `dead-letter-exchange`: The temporary exchange that is used to
            forward the task
        - `dead-letter-routing-key`: The queue we want the task to be
             ultimately sent to (in this case MGMTWORKER queue).
    2. Send the execution to that DLX
    3. When ttl is passed the task will automatically be sent to the
        MGMTWORKER queue and will be executed normally.
    """
    dlx_exchange = message['dlx_id']
    dlx_routing_key = message['dlx_id'] + '_queue'

    client = _get_amqp_client()
    send_handler = ScheduledExecutionHandler(exchange=dlx_exchange,
                                             exchange_type='direct',
                                             routing_key=dlx_routing_key,
                                             target_exchange=MGMTWORKER_QUEUE,
                                             target_routing_key=routing_key,
                                             ttl=message_ttl)
    client.add_handler(send_handler)
    with client:
        send_handler.publish(message)