Skip to content

Commit

Permalink
The email_address field cannot be mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosribas committed May 22, 2024
1 parent f26b496 commit cd89393
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ async def check_status(email_address: str, job_id: str):
@app.post("/submit-job")
async def submit_job(
*,
email_address: ty.Annotated[str, Form()],
sequence_file: UploadFile = File(...),
email_address: ty.Annotated[ty.Optional[str], Form()] = None,
sequence_file: UploadFile = File(None),
id: ty.Optional[str] = Form(None),
request: Request,
background_tasks: BackgroundTasks,
) -> api.SubmissionResponse:
url = request.url

if sequence_file is None:
raise HTTPException(
status_code=400, detail="Please upload a file in FASTA format"
)

try:
content = await sequence_file.read()
parsed = api.SubmittedRequest.parse(content.decode())
Expand All @@ -183,17 +188,20 @@ async def submit_job(
query = jd.Query()
query.id = id
query.sequences = "\n".join(parsed.sequences)
query.email_address = email_address
query.email_address = email_address if email_address else "[email protected]"

try:
job_id = await jd.JobDispatcher().submit_cmscan_job(query)
logger.info(f"Job submitted: {job_id}")
except HTTPException as e:
logger.error(f"Error submitting job. Error: {e}")
raise e

# Background task to check status
background_tasks.add_task(check_status, email_address, job_id)
if email_address:
# Background task to check status
background_tasks.add_task(check_status, email_address, job_id)
logger.info(f"Job submitted: {job_id}")
else:
logger.info(f"Job submitted programmatically: {job_id}")

return api.SubmissionResponse.build(
result_url=f"{url.scheme}://{url.netloc}/result/{job_id}",
Expand Down

0 comments on commit cd89393

Please sign in to comment.