Strongly typed tasks (partial celery replacement) ...
# our-work
d
Strongly typed tasks (partial celery replacement) for FastAPI on GCP. https://github.com/Adori/fastapi-cloud-tasks/ Define your tasks like FastAPI endpoints(because they are)
Copy code
@delayed_router.post("/{restaurant}/make_dinner")
def make_dinner(restaurant: str, recipe: Recipe):
    # Do a ton of work here.
Trigger them from anywhere:
Copy code
make_dinner.delay(restaurant="Taj", recipe=Recipe(ingredients=["Pav","Bhaji"]))
👍 2
🙌 1
h
Looks interesting! What's the significance of the delay method (also delayed router)
d
.delay
schedules a http request with Google's CloudTasks.
delayed_router
is just a router with
route_class
overriden. Full-ish example: https://github.com/Adori/fastapi-cloud-tasks/blob/main/examples/simple/main.py
If you're interested in the implementation: This is where the methods are added to the original endpoint.