Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Added on March 3, 2025 12:15PM
Likes: 0
Replies: 1
Hello, i'm trying to run a background task when my endpoint is call.
Here is a simple example of what i am trying to do.
import asyncio async def run_task_background(parameters):
job_uid = await run_task(parameters)
#add job_uid in a table def api_py_function(): asyncio.run(run_task_background(parameters))
return {"status": "Creating task"}
I tried a lot of different formulation but i always receive an error :
Failed to run function : <class 'TypeError'> : Object of type coroutine is not JSON serializable
Does somebody know what i am doing wrong ?
Thank you
Hi,
I tried to reproduce this issue by simulating an async task and calling it, and it worked fine:
import asyncio async def run_task(parameters): await asyncio.sleep(5) # Simulating async work return f"Task completed with parameters: {parameters}" async def run_task_background(parameters): job_uid = await run_task(parameters) def api_py_function(parameters): asyncio.run(run_task_background(parameters)) return {"status": "Creating task"}
Result:
{"status":"Creating task"}
Could you try this by adding the parameter in your api_py_function and see if the same error occurs?