1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
import time
from django.tasks import TaskContext, task
@task()
def noop_task(*args, **kwargs):
return None
@task
def noop_task_from_bare_decorator(*args, **kwargs):
return None
@task()
async def noop_task_async(*args, **kwargs):
return None
@task()
def calculate_meaning_of_life():
return 42
@task()
def failing_task_value_error():
raise ValueError("This Task failed due to ValueError")
@task()
def failing_task_system_exit():
raise SystemExit("This Task failed due to SystemExit")
@task()
def failing_task_keyboard_interrupt():
raise KeyboardInterrupt("This Task failed due to KeyboardInterrupt")
@task()
def complex_exception():
raise ValueError(ValueError("This task failed"))
@task()
def complex_return_value():
# Return something which isn't JSON serializable nor picklable.
return lambda: True
@task()
def exit_task():
exit(1)
@task()
def hang():
"""
Do nothing for 5 minutes
"""
time.sleep(300)
@task()
def sleep_for(seconds):
time.sleep(seconds)
@task(takes_context=True)
def get_task_id(context):
return context.task_result.id
@task(takes_context=True)
def test_context(context, attempt):
assert isinstance(context, TaskContext)
assert context.attempt == attempt
|