File: tasks.py

package info (click to toggle)
celery 5.5.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,188 kB
  • sloc: python: 64,417; sh: 795; makefile: 378
file content (21 lines) | stat: -rw-r--r-- 478 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pydantic import BaseModel

from celery import Celery

app = Celery('tasks', broker='amqp://')


class ArgModel(BaseModel):
    value: int


class ReturnModel(BaseModel):
    value: str


@app.task(pydantic=True)
def x(arg: ArgModel) -> ReturnModel:
    # args/kwargs type hinted as Pydantic model will be converted
    assert isinstance(arg, ArgModel)
    # The returned model will be converted to a dict automatically
    return ReturnModel(value=f"example: {arg.value}")