langflow/tests/utils.py
Gabriel Luiz Freitas Almeida fa1ebea378 🐛 fix(process.py): remove unnecessary session_id parameter in build_sorted_vertices function calls
🐛 fix(endpoints.py): remove unused import and type hinting to improve code readability and maintainability
🐛 fix(endpoints.py): fix incorrect import statement for TaskService
🐛 fix(endpoints.py): fix incorrect return value for get_task_status function
 feat(endpoints.py): add test case for async task processing to validate task completion and result
2023-09-15 18:16:25 -03:00

27 lines
833 B
Python

import time
def run_post(client, flow_id, headers, post_data):
response = client.post(
f"api/v1/process/{flow_id}",
headers=headers,
json=post_data,
)
assert response.status_code == 200, response.json()
return response.json()
# Helper function to poll task status
def poll_task_status(client, headers, task_id, max_attempts=20, sleep_time=1):
for _ in range(max_attempts):
task_status_response = client.get(
f"api/v1/task/{task_id}/status",
headers=headers,
)
if (
task_status_response.status_code == 200
and task_status_response.json()["status"] == "SUCCESS"
):
return task_status_response.json()
time.sleep(sleep_time)
return None # Return None if task did not complete in time