add celery example

This commit is contained in:
David Lord 2023-02-09 10:50:57 -08:00
parent dca8cf013b
commit 3f195248dc
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
9 changed files with 313 additions and 0 deletions

View 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}