Skip to content

Commit

Permalink
Extract timestamp logic into a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
kharus committed Jan 22, 2025
1 parent cf9de66 commit 63e997f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 11 additions & 6 deletions natural4-server/natural4_server/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ async def process_csv(request: Request) -> HTTPResponse:
# postprocessing: for petri nets: turn the DOT files into PNGs
# we run this asynchronously and block at the end before returning.
# ---------------------------------------------
timestamp, flowchart_tasks = await petri_post_process(target_folder)
timestamp = await extract_timestamp(target_folder)

flowchart_tasks = await petri_post_process(timestamp, target_folder)

# ---------------------------------------------
# postprocessing:
Expand Down Expand Up @@ -222,17 +224,20 @@ async def process_csv(request: Request) -> HTTPResponse:
)


async def petri_post_process(target_folder):
petri_folder = target_folder / "petri"
dot_path = anyio.Path(petri_folder / "LATEST.dot")
async def extract_timestamp(target_folder):
aajson_folder = target_folder / "aajson"
latest_aajson = anyio.Path(aajson_folder / "LATEST.json")
# dot_path resolves to something like 2025-01-06T03:00:52.dot
# stem is respectively a timestamp 2025-01-06T03:00:52
timestamp = (await dot_path.readlink()).stem
timestamp = (await latest_aajson.readlink()).stem

return timestamp

async def petri_post_process(timestamp, target_folder):
flowchart_tasks: asyncio.Task[None] = cyz.pipe(
get_flowchart_tasks(target_folder, timestamp), run_tasks)

return timestamp, flowchart_tasks
return flowchart_tasks


async def save_csv(request, target_folder, time_now):
Expand Down
4 changes: 3 additions & 1 deletion natural4-server/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def is_not_200(value):

@retry(retry=(retry_if_result(is_not_200)), wait=wait_fixed(5), stop=stop_after_delay(30))
def poll_url(client, url):
print(f"Waiting for {url}...")
path = url.split("/")
print(f"Waiting for {path[-2]}/{path[-1]}")

request, response = client.get(url)
return response.status

Expand Down

0 comments on commit 63e997f

Please sign in to comment.