Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
fixed background querying
Browse files Browse the repository at this point in the history
  • Loading branch information
leftmove committed Apr 30, 2024
1 parent fafa971 commit a7076c6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions routers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ async def background_query(query_type, cik_list, background, query_function):
cm.set_key_no_expiration(query_type, "running")

for cik in cik_list:
if len(running) < 10:
background.add_task(query_function, cik, background)
running.append(cik)

while len(running) >= max_processes:
for run in running:
process = database.find_log(run, {"status": 1})
Expand All @@ -63,10 +67,6 @@ async def background_query(query_type, cik_list, background, query_function):

await asyncio.sleep(5)

if len(running) < 10:
background.add_task(query_function, cik, background)
running.append(cik)

cm.set_key_no_expiration(query_type, "stopped")


Expand All @@ -83,23 +83,11 @@ async def query_top(password: str, background: BackgroundTasks):
return {"description": "Started querying filers."}


def create_error(cik, e):
stamp = str(datetime.now())
cwd = os.getcwd()
with open(f"{cwd}/static/errors/error-general-{stamp}.log", "w") as f:
error_string = f"Failed to Query Filer {cik}\n{repr(e)}\n{format_exc()}"
f.write(error_string)


@router.get("/restore", status_code=200)
async def progressive_restore(password: str, background: BackgroundTasks):
if password != os.environ["ADMIN_PASSWORD"]:
raise HTTPException(detail="Unable to give access.", status_code=403)

restore = cm.get_key("restore")
if restore and restore == "running":
raise HTTPException(status_code=429, detail="Restore already running.")

filers = database.find_filers({}, {"cik": 1})
all_ciks = [filer["cik"] for filer in filers]

Expand All @@ -108,6 +96,14 @@ async def progressive_restore(password: str, background: BackgroundTasks):
return {"description": "Started progressive restore of filers."}


def create_error(cik, e):
stamp = str(datetime.now())
cwd = os.getcwd()
with open(f"{cwd}/static/errors/error-general-{stamp}.log", "w") as f:
error_string = f"Failed to Query Filer {cik}\n{repr(e)}\n{format_exc()}"
f.write(error_string)


@router.get("/backup", status_code=201)
async def backup(password: str, background: BackgroundTasks):
if password != os.environ["ADMIN_PASSWORD"]:
Expand Down

0 comments on commit a7076c6

Please sign in to comment.