From 82691dd9fbd32f9f8cac7a89c525a5adf6e1f339 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Wed, 5 Oct 2022 16:57:04 -0400 Subject: [PATCH] Added some additional doc strings --- project/users/views.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/project/users/views.py b/project/users/views.py index bd79013..e6d9c13 100644 --- a/project/users/views.py +++ b/project/users/views.py @@ -16,7 +16,7 @@ templates = Jinja2Templates(directory="project/users/templates") def api_call(email: str): # pylint: disable=unused-argument - # used for testing a failed api call + """Used for testing a failed api call""" if random.choice([0, 1]): raise Exception("random processing error") @@ -31,12 +31,21 @@ def form_example_get(request: Request): @users_router.post("/form/") def form_example_post(user_body: UserBody): + """Accepts form data, and relays request to the task queue. + + Returns the task id, which can be used with the /task_status/ + endpoint to monitor status of the submitted requests. + """ task = sample_task.delay(user_body.email) return JSONResponse({"task_id": task.task_id}) @users_router.get("/task_status/") def task_status(task_id: str): + """Check async task result. + + Endpoint is used for XHR short polling to check the task status. + """ task = AsyncResult(task_id) state = task.state @@ -55,6 +64,7 @@ def task_status(task_id: str): @users_router.post("/webhook_test/") def webhook_test(): + """Endpoint simulating the synchronous handling of a webhook request to another service.""" if not random.choice([0, 1]): # mimic an error raise Exception() @@ -66,6 +76,10 @@ def webhook_test(): @users_router.post("/webhook_test_async/") def webhook_test_async(): + """End point simulating async handling of a webhook request to another service. + + curl -X POST http://localhost:8010/users/webhook_test_async/ -d {'data':'ping'} + """ task = task_process_notification.delay() print(task.id) return "pong"