2020-01-21 06:35:58 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from celery import shared_task
|
|
|
|
|
|
|
|
from judge.utils.celery import Progress
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
__all__ = ("success", "failure", "progress")
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def success():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def failure():
|
2022-05-14 17:57:27 +00:00
|
|
|
raise RuntimeError("This task always fails.")
|
2020-01-21 06:35:58 +00: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)
|