0

我目前正在研究一个应该通过队列触发器执行的 Azure 函数。问题是它不能正常工作。

有时队列消息未处理并卡住。更常见的是,azure 函数执行会卡住。就像执行了一些代码行,但之后它被卡住并且没有进一步执行。它也没有出现在我可以跟踪问题的日志中。我已经从 azure 门户检查了该 azure 功能的“监视器”选项卡,但找不到任何问题。

Http 触发 Azure 函数

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
        )

队列触发 Azure 函数

 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)

可能是什么问题?我怎样才能追踪它?有人可以帮我解决这个问题吗?谢谢

4

0 回答 0