Skip to content

Commit

Permalink
enable downloading expired jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
rlellep committed Nov 22, 2022
1 parent 87bc571 commit a26569e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/api/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ async def create_job(response: Response,
async def get_job_info(job_id: str, session: AsyncSession = Depends(database.get_session)):
return await database.read_job(session, job_id)

'''
@router.get('/{job_id}/stop', response_model=JobInfo, response_model_exclude_none=True,
responses={404: {"model": ErrorMessage},
400: {"model": ErrorMessage}},
dependencies=[Depends(check_uuid)])
async def get_job_info(job_id: str, session: AsyncSession = Depends(database.get_session)):
job_info = await database.read_job(session, job_id)
if job_info.state in [State.QUEUED, State.IN_PROGRESS, State.COMPLETED]:
await database.update_job(session, job_id, State.EXPIRED)
return await database.read_job(session, job_id)
'''

@router.get('/{job_id}/audiobook', response_class=FileResponse,
responses={404: {"model": ErrorMessage},
Expand All @@ -87,8 +98,9 @@ async def get_job_info(job_id: str, session: AsyncSession = Depends(database.get
async def get_audiobook(job_id: str, session: AsyncSession = Depends(database.get_session)):
job_info = await database.read_job(session, job_id)
file_path = os.path.join(api_settings.storage_path, f"{job_id}.zip")
if job_info.state == State.COMPLETED and os.path.exists(file_path):
await database.update_job(session, job_id, State.EXPIRED)
if job_info.state in [State.COMPLETED, State.EXPIRED] and os.path.exists(file_path):
if job_info.state != State.EXPIRED:
await database.update_job(session, job_id, State.EXPIRED)
return FileResponse(file_path, filename=f"{job_id}.zip")


Expand Down

0 comments on commit a26569e

Please sign in to comment.