示例#1
0
 def do_work():
     nonlocal failure_time, success_time
     if not failure_time:
         failure_time = current_millis()
         raise RuntimeError("First failure.")
     else:
         success_time = current_millis()
         succeeded.set()
示例#2
0
def join_all(joinables, timeout):
    """Wait on a list of objects that can be joined with a total
    timeout represented by ``timeout``.

    Parameters:
      joinables(object): Objects with a join method.
      timeout(int): The total timeout in milliseconds.
    """
    started, elapsed = current_millis(), 0
    for ob in joinables:
        ob.join(timeout=timeout / 1000)
        elapsed = current_millis() - started
        timeout = max(0, timeout - elapsed)
示例#3
0
def test_rabbitmq_actors_can_have_their_messages_delayed(rabbitmq_broker, rabbitmq_worker):
    # Given that I have a database
    start_time, run_time = current_millis(), None

    # And an actor that records the time it ran
    @remoulade.actor
    def record():
        nonlocal run_time
        run_time = current_millis()

    # And this actor is declared
    rabbitmq_broker.declare_actor(record)

    # If I send it a delayed message
    record.send_with_options(delay=1000)

    # Then join on the queue
    rabbitmq_broker.join(record.queue_name)
    rabbitmq_worker.join()

    # I expect that message to have been processed at least delayed milliseconds later
    assert run_time - start_time >= 1000
示例#4
0
 def record():
     nonlocal run_time
     run_time = current_millis()
示例#5
0
import os
import platform
import time
from pathlib import Path

import pytest

import remoulade
from remoulade.brokers.rabbitmq import RabbitmqBroker
from remoulade.common import current_millis

broker = RabbitmqBroker(max_priority=10)
remoulade.set_broker(broker)

loaded_at = current_millis()

CURRENT_PLATFORM = platform.python_implementation()
CURRENT_OS = platform.system()


@remoulade.actor()
def write_loaded_at(filename):
    with open(filename, "w") as f:
        f.write(str(loaded_at))


broker.declare_actor(write_loaded_at)


@pytest.mark.skipif(os.getenv("CI") == "1", reason="test skipped on CI")
@pytest.mark.skipif(CURRENT_PLATFORM == "PyPy",