Skip to content

Commit c94c8eb

Browse files
committed
added log streaming with --wait flag
1 parent 4d1ec3d commit c94c8eb

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

chipflow_lib/steps/silicon.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,15 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
179179
logger.info(f"Submitted design: {resp_data}")
180180
build_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}"
181181
build_status_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}/status"
182+
log_stream_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}/logs?follow=true"
182183

183184
print(f"Design submitted successfully! Build URL: {build_url}")
184185

185186
# Poll the status API until the build is completed or failed
187+
stream_event_counter = 0
186188
if wait:
187189
while True:
190+
logger.info(f"Polling build status...")
188191
status_resp = requests.get(
189192
build_status_url,
190193
auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"])
@@ -203,10 +206,32 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
203206
elif build_status == "failed":
204207
print("Build failed.")
205208
exit(1)
206-
207-
# Wait before polling again
208-
time.sleep(10)
209-
209+
elif build_status == "running":
210+
print("Build running.")
211+
# Wait before polling again
212+
# time.sleep(10)
213+
# Attempt to stream logs rather than time.sleep
214+
try:
215+
if stream_event_counter > 1:
216+
logger.warning("Log streaming may have been interrupted. Some logs may be missing.")
217+
logger.warning(f"Check {build_url}")
218+
stream_event_counter += 1
219+
with requests.get(
220+
log_stream_url,
221+
auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]),
222+
stream=True
223+
) as log_resp:
224+
if log_resp.status_code == 200:
225+
for line in log_resp.iter_lines():
226+
if line:
227+
print(line.decode("utf-8")) # Print logs in real-time
228+
sys.stdout.flush()
229+
else:
230+
logger.warning(f"Failed to stream logs: {log_resp.text}")
231+
except requests.RequestException as e:
232+
logger.error(f"Error while streaming logs: {e}")
233+
pass
234+
time.sleep(10) # Wait before polling again
210235
else:
211236
# Log detailed information about the failed request
212237
logger.error(f"Request failed with status code {resp.status_code}")

0 commit comments

Comments
 (0)