Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tenacity for polling #260

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion natural4-server/natural4_server/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ async def petri_post_process(target_folder):
# stem is respectively a timestamp 2025-01-06T03:00:52
timestamp = (await dot_path.readlink()).stem

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

return timestamp, flowchart_tasks

Expand Down
1 change: 1 addition & 0 deletions natural4-server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dev-dependencies = [
"pre-commit<4.0.0,>=3.6.2",
"coverage<8.0.0,>=7.4.3",
"pytest-asyncio>=0.24.0",
"tenacity>=9.0.0",
]

[tool.ruff]
Expand Down
39 changes: 19 additions & 20 deletions natural4-server/tests/test_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from time import sleep, time
from time import sleep

from sanic import Sanic
from sanic.application.constants import ServerStage
from sanic_testing.reusable import ReusableClient
from tenacity import retry, retry_if_result, stop_after_delay, wait_fixed


def is_not_200(value):
"""Return True if value is None"""
return value != 200

@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}...")
request, response = client.get(url)
return response.status


def test_post(app: Sanic, post_data):
Expand Down Expand Up @@ -32,22 +44,9 @@ def test_post(app: Sanic, post_data):
request, response_json = client.get(f"{workdir_url}/petri/LATEST-small.png")
assert response_json.status == 200

start_time = time()
while time() - start_time < 60:
print("Waiting for PDF...")
request, response_pdf = client.get(f"{workdir_url}/docx/LATEST.docx")
if response_pdf.status != 200:
sleep(5)
else:
break

start_time = time()
while time() - start_time < 60:
print("Waiting for PDF...")
request, response_pdf = client.get(f"{workdir_url}/pdf/LATEST.pdf")
if response_pdf.status != 200:
sleep(5)
else:
break

assert response_pdf.status == 200
response_docx = poll_url(client, f"{workdir_url}/docx/LATEST.docx")
assert response_docx == 200

response_pdf = poll_url(client, f"{workdir_url}/pdf/LATEST.pdf")

assert response_pdf == 200
11 changes: 11 additions & 0 deletions natural4-server/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading