Skip to content

Commit fc9caae

Browse files
committed
Core REST API bugfixes to detect timeouts and resolve potential error with overloaded status variable.
1 parent 04d219c commit fc9caae

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

anms-core/anms/routes/network_manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@ def do_nm_put_hex_eid(eid: str, ari: str):
9191
logger.info('post to nm manager %s with eid %s and data %s' % (url, eid, ari))
9292

9393
try:
94-
request = requests.post(url=url, data=ari, headers={'Content-Type': 'text/plain'})
94+
request = requests.post(url=url,
95+
data=ari,
96+
headers={'Content-Type': 'text/plain'},
97+
timeout=(2.0, 8.0) # 2s for manager to connect, 8s for it to respond
98+
)
99+
except requests.exceptions.ConnectTimeout:
100+
return status.HTTP_504_GATEWAY_TIMEOUT
101+
except requests.exceptions.ReadTimeout:
102+
return status.HTTP_504_GATEWAY_TIMEOUT
103+
except requests.exceptions.Timeout:
104+
return status.HTTP_504_GATEWAY_TIMEOUT
95105
except Exception:
96106
return status.HTTP_500_INTERNAL_SERVER_ERROR
97107
return request.status_code

anms-core/anms/routes/transcoder.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ async def transcoder_put_input_cbor(input_cbor: str):
8585
session.refresh(c1)
8686
transcoder_log_id = c1.transcoder_log_id
8787
session.commit()
88-
status = "Submitted ARI to transcoder"
88+
state = "Submitted ARI to transcoder"
8989
else:
9090
# the input_ari has already been submitted
91-
status = "ARI previously submitted, check log"
91+
state = "ARI previously submitted, check log"
9292
transcoder_log_id = curr_uri.transcoder_log_id
9393

9494
logger.info('PUBLISH to transcode/CoreFacing/Outgoing, msg = %s' % msg)
9595
MQTT_CLIENT.publish("transcode/CoreFacing/Outgoing", msg)
9696

97-
return {"id": transcoder_log_id, "status": status}
97+
return {"id": transcoder_log_id, "status": state}
9898

9999

100100
@router.get("/ui/incoming/await/{cbor}/hex", status_code=status.HTTP_200_OK)
@@ -200,16 +200,16 @@ def transcoder_put_str(input_ari: str):
200200
session.refresh(c1)
201201
transcoder_log_id = c1.transcoder_log_id
202202
session.commit()
203-
status = "Submitted ARI to transcoder"
203+
state = "Submitted ARI to transcoder"
204204
else:
205205
# the input_ari has already been submitted
206-
status = "ARI previously submitted, check log"
206+
state = "ARI previously submitted, check log"
207207
transcoder_log_id = curr_uri.transcoder_log_id
208208

209209
logger.info('PUBLISH to transcode/CoreFacing/Outgoing, msg = %s' % msg)
210210
MQTT_CLIENT.publish("transcode/CoreFacing/Outgoing", msg)
211211

212-
return {"id": transcoder_log_id, "status": status}
212+
return {"id": transcoder_log_id, "status": state}
213213

214214

215215

@@ -223,21 +223,24 @@ async def transcoder_send_ari_str(eid: str, ari: str):
223223
# Retrieve details and wait for completion
224224
retries = 10
225225
while True:
226+
# Wait for request to process before checking state
227+
await asyncio.sleep(1)
228+
226229
info = do_transcoder_log_by_id(idinfo["id"])
230+
227231
if info.parsed_as != "pending":
228232
break
229233
if retries <= 0:
230234
return { "idinfo" : idinfo, "info" : info, "status" : 504 }
231-
await asyncio.sleep(1)
232235
retries -= 1
233236

234237
if info.parsed_as == "ERROR":
235238
return { "idinfo" : idinfo, "info" : info, "status" : 500 }
236-
239+
237240
# Publish
238-
status = do_nm_put_hex_eid( eid, info.cbor )
241+
state = do_nm_put_hex_eid( eid, info.cbor )
239242

240-
return { "idinfo" : idinfo, "info" : info, "status" : status }
243+
return { "idinfo" : idinfo, "info" : info, "status" : state }
241244
except Exception as e:
242245
logger.exception(e)
243246
return status.HTTP_500_INTERNAL_SERVER_ERROR

0 commit comments

Comments
 (0)