0

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

Hunzla Ali
  • 383
  • 2
  • 5
  • 22
  • Please add the code of your function. Also, have you already checked the application insights for any useful information? – Anupam Chand Oct 25 '21 at 03:42
  • I have updated question @AnupamChand – Hunzla Ali Oct 25 '21 at 17:49
  • 1
    Please remove the pictures and insert the code so the community can copy paste the code easily. – Anupam Chand Oct 26 '21 at 01:11
  • Updated with code – Hunzla Ali Oct 26 '21 at 07:08
  • Does this run fine locally? – Nikhil Vartak Oct 26 '21 at 09:23
  • I have not tested that locally. Deploy on server and testing on there – Hunzla Ali Oct 28 '21 at 09:23
  • Enable ```Application insights``` for your Azure function app, and you must be able to see the trace messages to know upto which part of your code is executing. – Anand Sowmithiran Nov 09 '21 at 04:36
  • Actually I am using multiprocessing lib. In main function, I am calling another function using Process.Start(). And after starting the process, main function return response. Called function process in background. I have checked monitor log and also Application insight but as main function executed successfully so it did not track called function. I am facing stuck issues in called function. @AnandSowmithiran – Hunzla Ali Aug 08 '22 at 08:11

0 Answers0