How to use the dramatiq.Worker function in dramatiq

To help you get started, we’ve selected a few dramatiq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bogdanp / dramatiq / tests / common.py View on Github external
def worker(*args, **kwargs):
    try:
        worker = Worker(*args, **kwargs)
        worker.start()
        yield worker
    finally:
        worker.stop()
github Bogdanp / dramatiq / tests / benchmarks / test_rabbitmq.py View on Github external
def process_messages():
        worker = dramatiq.Worker(rabbitmq_broker)
        worker.start()
        rabbitmq_broker.join(rabbitmq_random_queue)
        worker.stop()
github Bogdanp / django_dramatiq_example / dashboard / tests.py View on Github external
def setUp(self):
        super().setUp()

        self.broker = dramatiq.get_broker()
        self.worker = dramatiq.Worker(self.broker, worker_timeout=100)
        self.worker.start()
github Bogdanp / dramatiq / tests / test_rabbitmq.py View on Github external
def test_rabbitmq_broker_can_enqueue_messages_with_priority(rabbitmq_broker):
    max_priority = 10
    message_processing_order = []
    queue_name = "prioritized"

    # Given that I have an actor that store priorities
    @dramatiq.actor(queue_name=queue_name)
    def do_work(message_priority):
        message_processing_order.append(message_priority)

    worker = Worker(rabbitmq_broker, worker_threads=1)
    worker.queue_prefetch = 1
    worker.start()
    worker.pause()

    try:
        # When I send that actor messages with increasing priorities
        for priority in range(max_priority):
            do_work.send_with_options(args=(priority,), broker_priority=priority)

        # And then tell the broker to wait for all messages
        worker.resume()
        rabbitmq_broker.join(queue_name, timeout=5000)
        worker.join()

        # I expect the stored priorities to be saved in decreasing order
        assert message_processing_order == list(reversed(range(max_priority)))
github Bogdanp / dramatiq / tests / benchmarks / test_redis.py View on Github external
def process_messages():
        worker = dramatiq.Worker(redis_broker)
        worker.start()
        redis_broker.join(throughput.queue_name)
        worker.stop()
github Bogdanp / apistar_dramatiq / tests / test_actor_decorator.py View on Github external
def worker(broker):
    worker = dramatiq.Worker(broker, worker_timeout=100)
    worker.start()
    yield worker
    worker.stop()
github Bogdanp / dramatiq / examples / basic / profile_example.py View on Github external
def main(args):
    broker = dramatiq.get_broker()
    broker.emit_after("process_boot")
    worker = dramatiq.Worker(broker, worker_threads=1)
    worker.start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    worker.stop()
    broker.close()
github Bogdanp / dramatiq / examples / crawler / profile_example.py View on Github external
def main(args):
    broker = dramatiq.get_broker()
    broker.emit_after("process_boot")
    worker = dramatiq.Worker(broker, worker_threads=1)
    worker.start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    worker.stop()
    broker.close()