Removed redundant delete_temp_file function in app.py, using tasks.delete_temp_file instead.
This commit is contained in:
parent
5268696f39
commit
40d670fc9a
9
app.py
9
app.py
@ -3,7 +3,7 @@ import tempfile
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# Assuming Celery is already set up and imported correctly in the project.
|
# Assuming Celery is already set up and imported correctly in the project.
|
||||||
from celery import shared_task # Import your Celery instance here.
|
from tasks import delete_temp_file # Import your Celery task here.
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@ -17,12 +17,7 @@ async def upload_file(file: UploadFile = File(...)):
|
|||||||
with open(temp_file_path, 'wb') as f:
|
with open(temp_file_path, 'wb') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
# Call a Celery task that deletes the file after processing.
|
# Call the Celery task that deletes the file after processing.
|
||||||
delete_temp_file.delay(temp_file_path) # Assuming this is your Celery task name.
|
delete_temp_file.delay(temp_file_path) # Assuming this is your Celery task name.
|
||||||
|
|
||||||
return {"filename": file.filename}
|
return {"filename": file.filename}
|
||||||
|
|
||||||
# Define the Celery task to delete the temporary file
|
|
||||||
@shared_task
|
|
||||||
def delete_temp_file(file_path):
|
|
||||||
os.remove(file_path)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user