Sunday 29 November 2020

How to send a progress of operation in a FastAPI app?

I have deployed a fastapi endpoint,

from fastapi import FastAPI, UploadFile
from typing import List

app = FastAPI()

@app.post('/work/test')
async def testing(files: List(UploadFile)):
    for i in files:
        .......
        # do a lot of operations on each file

        # after than I am just writing that processed data into mysql database
        # cur.execute(...)
        # cur.commit()
        .......
    
    # just returning "OK" to confirm data is written into mysql
    return {"response" : "OK"}

I can request output from the API endpoint and its working fine for me perfectly.

Now, the biggest challenge for me to know how much time it is taking for each iteration. Because in the UI part (those who are accessing my API endpoint) I want to help them show a progress bar (TIME TAKEN) for each iteration/file being processed.

Is there any possible way for me to achieve it? If so, please help me out on how can I proceed further?

Thank you.



from How to send a progress of operation in a FastAPI app?

No comments:

Post a Comment