Removed redundant delete_temp_file function in app.py, using tasks.delete_temp_file instead.

This commit is contained in:
Timothy Farrell (aider) 2024-07-15 11:24:18 -05:00
parent 5268696f39
commit 40d670fc9a

9
app.py
View File

@ -3,7 +3,7 @@ import tempfile
import os
# 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()
@ -17,12 +17,7 @@ async def upload_file(file: UploadFile = File(...)):
with open(temp_file_path, 'wb') as f:
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.
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)