How to use the dramatiq.actor 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 / test_rabbitmq.py View on Github external
    @dramatiq.actor(max_retries=0)
    def do_work():
        raise RuntimeError("failed")
github Bogdanp / dramatiq / tests / test_results.py View on Github external
    @dramatiq.actor
    def do_work():
        return 42
github Bogdanp / dramatiq / tests / test_actors.py View on Github external
    @dramatiq.actor(actor_name="foo")
    def add(x, y):
        return x + y
github Bogdanp / dramatiq / tests / test_results.py View on Github external
    @dramatiq.actor(store_results=True)
    def do_work():
        return 42
github Bogdanp / dramatiq / tests / benchmarks / test_rabbitmq_cli.py View on Github external
@dramatiq.actor(queue_name="benchmark-fib", broker=broker)
def fib(n):
    x, y = 1, 1
    while n > 2:
        x, y = x + y, x
        n -= 1
    return x
github Bogdanp / dramatiq / tests / benchmarks / test_rabbitmq.py View on Github external
    @dramatiq.actor(queue_name=rabbitmq_random_queue)
    def throughput():
        pass
github Bogdanp / dramatiq / tests / test_actors.py View on Github external
    @dramatiq.actor(max_retries=99, min_backoff=5000, max_backoff=50000)
    def do_work():
        attempts.append(1)
        raise RuntimeError("failure")
github Bogdanp / dramatiq / benchmarks / bench.py View on Github external
if p == 1:
        duration = 10
    elif p <= 30:
        duration = 5
    elif p <= 50:
        duration = 3
    else:
        duration = 1

    time.sleep(duration)
    with memcache_pool.reserve() as client:
        client.incr(counter_key)


dramatiq_fib_bench = dramatiq.actor(fib_bench)
dramatiq_latency_bench = dramatiq.actor(latency_bench)

celery_fib_bench = celery_app.task(name="fib-bench", acks_late=True)(fib_bench)
celery_latency_bench = celery_app.task(name="latency-bench", acks_late=True)(latency_bench)


def benchmark_arg(value):
    benchmarks = ("fib", "latency")
    if value not in benchmarks:
        raise argparse.ArgumentTypeError(f"benchmark must be one of {benchmarks!r}")
    return value


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--benchmark", help="the benchmark to run",
github QingdaoU / OnlineJudge / judge / tasks.py View on Github external
@dramatiq.actor(**DRAMATIQ_WORKER_ARGS())
def judge_task(submission_id, problem_id):
    uid = Submission.objects.get(id=submission_id).user_id
    if User.objects.get(id=uid).is_disabled:
        return
    JudgeDispatcher(submission_id, problem_id).judge()