Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@dramatiq.actor(max_retries=0)
def do_work():
raise RuntimeError("failed")
@dramatiq.actor
def do_work():
return 42
@dramatiq.actor(actor_name="foo")
def add(x, y):
return x + y
@dramatiq.actor(store_results=True)
def do_work():
return 42
@dramatiq.actor
def do_work():
pass
@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
@dramatiq.actor(queue_name=rabbitmq_random_queue)
def throughput():
pass
@dramatiq.actor(max_retries=99, min_backoff=5000, max_backoff=50000)
def do_work():
attempts.append(1)
raise RuntimeError("failure")
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",
@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()