Skip to content

Commit

Permalink
apscheduler used in place of fastapi background tasks for generating …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
nrjadkry committed Nov 7, 2023
1 parent 0a3955f commit 3b60162
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,20 +631,50 @@ async def generate_files(
db, task_id=background_task_id, project_id=project_id
)

log.debug(f"Submitting {background_task_id} to background tasks stack")
background_tasks.add_task(
from datetime import datetime

from apscheduler.schedulers.asyncio import AsyncIOScheduler

sched = AsyncIOScheduler()
sched.start()

job = sched.add_job(
project_crud.generate_appuser_files,
db,
project_id,
extract_polygon,
contents,
extracts_contents if data_extracts else None,
xform_title,
file_ext[1:] if upload else "xls",
background_task_id,
"date",
run_date=datetime.now(),
args=[
db,
project_id,
extract_polygon,
contents,
extracts_contents if data_extracts else None,
xform_title,
file_ext[1:] if upload else "xls",
background_task_id,
],
id="unique_id",
)

return {"Message": f"{project_id}", "task_id": f"{background_task_id}"}
print("Job = ", job)

# log.debug(f"Submitting {background_task_id} to background tasks stack")
# background_tasks.add_task(
# project_crud.generate_appuser_files,
# db,
# project_id,
# extract_polygon,
# contents,
# extracts_contents if data_extracts else None,
# xform_title,
# file_ext[1:] if upload else "xls",
# background_task_id,
# )

return {
"Message": f"{project_id}",
"task_id": f"{background_task_id}",
# "job":job
}


@router.post("/update-form/{project_id}")
Expand Down

0 comments on commit 3b60162

Please sign in to comment.