forked from orbit-oss/flask
add celery example
This commit is contained in:
parent
dca8cf013b
commit
3f195248dc
9 changed files with 313 additions and 0 deletions
23
examples/celery/src/task_app/tasks.py
Normal file
23
examples/celery/src/task_app/tasks.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import time
|
||||
|
||||
from celery import shared_task
|
||||
from celery import Task
|
||||
|
||||
|
||||
@shared_task(ignore_result=False)
|
||||
def add(a: int, b: int) -> int:
|
||||
return a + b
|
||||
|
||||
|
||||
@shared_task()
|
||||
def block() -> None:
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
@shared_task(bind=True, ignore_result=False)
|
||||
def process(self: Task, total: int) -> object:
|
||||
for i in range(total):
|
||||
self.update_state(state="PROGRESS", meta={"current": i + 1, "total": total})
|
||||
time.sleep(1)
|
||||
|
||||
return {"current": total, "total": total}
|
||||
Loading…
Add table
Add a link
Reference in a new issue