NDOJ/judge/tasks/demo.py

26 lines
427 B
Python
Raw Normal View History

2020-01-21 15:35:58 +09:00
import time
from celery import shared_task
from judge.utils.celery import Progress
2022-05-14 12:57:27 -05:00
__all__ = ("success", "failure", "progress")
2020-01-21 15:35:58 +09:00
@shared_task
def success():
pass
@shared_task
def failure():
2022-05-14 12:57:27 -05:00
raise RuntimeError("This task always fails.")
2020-01-21 15:35:58 +09:00
@shared_task(bind=True)
def progress(self, seconds=10):
with Progress(self, seconds) as p:
for i in range(seconds):
time.sleep(1)
p.did(1)