I'm currently working on an Azure function which should get executed through an Queue-Trigger. The problem is that it doesn't work as it should.
Sometimes queue messages not processed and get stuck. And more often, azure function execution get stuck. Like some of line of code executed but after that it get stuck and did not execute further. Also it did not come to Logs from where I can track the issue. I have checked the "Monitor" tab of that azure function from azure portal but could not find any issue.
Http Trigger Azure Function
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
videoId = req.params.get('videoId')
projectId = req.params.get('projectId')
startTime = req.params.get('startTime')
endTime = req.params.get('endTime')
chunk = req.params.get('chunk')
if videoId:
queue_service = QueueClient.from_connection_string(conn_str=os.environ['QueueStorageAccountConStr'],
queue_name=os.environ['QueueNameVAAIEventDetectNuig'])
logging.info('videoId:'+str(videoId))
logging.info('projectId:'+str(projectId))
logging.info('startTime:'+str(startTime))
logging.info('endTime:'+str(endTime))
logging.info('chunk:'+str(chunk))
param = '{"videoId":"' + videoId +'","projectId":"' + projectId +'","startTime":"' + startTime +'","endTime":"' + endTime +'","chunk":"' + chunk +'"}'
param_str = str(param)
param_byte = param_str.encode('ascii')
queue_service.message_encode_policy = BinaryBase64EncodePolicy()
queue_service.message_decode_policy = BinaryBase64DecodePolicy()
queue_service.send_message(
queue_service.message_encode_policy.encode(content=param_byte)
)
return func.HttpResponse(f"Video ID, {videoId}. Added to event detect infer Queue.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a videoId in the query string or in the request body for a personalized response.",
status_code=200
)
Queue Trigger Azure Function
def main(msg: func.QueueMessage) -> None:
config = config_parser.get_default_config()
raw = msg.get_body().decode('utf-8')
logging.info(raw)
logging.info(raw)
params=json.loads(raw)
videoId = params["videoId"]
projectId = params["projectId"]
startTime =float(params["startTime"])
endTime = float(params["endTime"])
chunk = params["chunk"]
try:
db.InsertLogs(projectId,videoId,"vaeventdetectnuig_"+str(chunk)+"","on main","start")
db.InsertLogs(projectId,videoId,"AI Event Detection","ProjectRenderingStatus","start")
if(startTime==1):
db.UpdateProjectStatus(projectId,3)
# Main code start from here
db.InsertLogs(projectId,videoId,"vaeventdetectnuig_"+str(chunk)+"","before download","start")
# old code
download_input_video(videoId,config['input']['video_path'])
# Continue coding
# It stuck during this code execution
except Exception as e:
logging.info("exception in detection")
logging.info(e)
What can be the issue? How can I track that? Can someone please help me regarding this? Thanks