Skip to content

Commit

Permalink
fix(backend): generating project files passing project id to backgrou…
Browse files Browse the repository at this point in the history
…nd task (#1708)

* fix: generating project files passing project id to background task

* fix: updated docstring for project_id parameter
  • Loading branch information
Sujanadh authored Jul 25, 2024
1 parent 15036c7 commit 3b8eac9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ async def generate_odk_central_project_content(

async def generate_project_files(
db: Session,
project: db_models.DbProject,
project_id: int,
custom_form: Optional[BytesIO],
form_file_ext: str,
background_task_id: Optional[uuid.UUID] = None,
Expand All @@ -900,13 +900,13 @@ async def generate_project_files(
Args:
db (Session): the database session.
project (DbProject): FMTM database project.
project_id(int): id of the FMTM project.
custom_form (BytesIO): the xls file to upload if we have a custom form
form_file_ext (str): weather the form is xls, xlsx or xml
background_task_id (uuid): the task_id of the background task.
"""
try:
project_id = project.id
project = await get_project_by_id(db, project_id)
form_category = project.xform_category
log.info(f"Starting generate_project_files for project {project_id}")
odk_credentials = await project_deps.get_odk_credentials(db, project_id)
Expand Down
7 changes: 4 additions & 3 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ async def generate_files(
json (JSONResponse): A success message containing the project ID.
"""
project = project_user_dict.get("project")
project_id = project.id

log.debug(f"Generating media files tasks for project: {project.id}")

Expand All @@ -738,16 +739,16 @@ async def generate_files(
db.commit()

# Create task in db and return uuid
log.debug(f"Creating export background task for project ID: {project.id}")
log.debug(f"Creating export background task for project ID: {project_id}")
background_task_id = await project_crud.insert_background_task_into_database(
db, project_id=str(project.id)
db, project_id=project_id
)

log.debug(f"Submitting {background_task_id} to background tasks stack")
background_tasks.add_task(
project_crud.generate_project_files,
db,
project,
project_id,
BytesIO(custom_xls_form) if custom_xls_form else None,
file_ext,
background_task_id,
Expand Down

0 comments on commit 3b8eac9

Please sign in to comment.