简体   繁体   English

Azure 函数未执行

[英]Azure function doesn't get executed

I'm currently working on an Azure function which should get executed through an Queue-Trigger.我目前正在研究一个应该通过队列触发器执行的 Azure 函数。 The problem is that it doesn't work as it should.问题是它不能正常工作。

This is my __init__.py file:这是我的__init__.py文件:

all imports
...
def main(req: func.QueueMessage, res: func.Out[str]) -> func.QueueMessage:

    print(req)

    cmi_guid = req.get_body().decode('utf-8')
    
    logging.info('Received message: %s', req.get_body().decode('utf-8'))

    logging.info('Received message FULL: %s', req)

    tempFilePath = tempfile.gettempdir()
    print(tempFilePath)

    
    infile = cmi_guid + '.xlsx'
    outfile = cmi_guid + '_output.xlsx'
    local_in_file_path = os.path.join(tempFilePath, infile)
    local_out_file_path = os.path.join(tempFilePath, outfile)

    logging.info('Got temp file path: %s', tempFilePath)

    delete_files(tempFilePath, ".xlsx")
    logging.info('Deleted xlsx files in temp directory')

    blob_service_client = BlobServiceClient.from_connection_string(<MyConnectionString>)
    container_name = "cmi"
    # Create a blob client using the local file name as the name for the blob
    blob_client = blob_service_client.get_blob_client(container=container_name, blob=infile)

    with open(local_in_file_path, "wb") as download_file:
        download_file.write(blob_client.download_blob().readall())

    logging.info('Received input file from blob')

    df_out = start_forecast(local_in_file_path)
    with pd.ExcelWriter(local_out_file_path, engine='xlsxwriter') as writer:  
        df_out.to_excel(writer, sheet_name='Forecast', index=False)

    blob_client = blob_service_client.get_blob_client(container=container_name, blob=outfile)

    try:
        with open(local_out_file_path, "rb") as data:
            blob_client.upload_blob(data)
    except Exception as e:
        logging.info('Exception when uploading blob: %s', e)

    logging.info('Done uploading blob to storage')
    # res.set(cmi_guid)
    return cmi_guid

That is my function.json :那是我的function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "req",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "cmi-input",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "res",
      "type": "queue",
      "direction": "out",
      "queueName": "cmi-output",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

Thats my local.settings.json :那是我的local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": <MyConnectionString>,
    "MyStorageAccountConnection": <MyConnectionString>
  }
}

I have created for every value in the local.settings.json an application setting.我为local.settings.json的每个值创建了一个应用程序设置。

When I now upload an file to the cmi-input Queue then the Azure function should actually be started and a file should be loaded into a Blob container (is written in the code).当我现在将文件上传到 cmi-input 队列时,Azure 函数应该实际启动,并且文件应该加载到 Blob 容器中(写在代码中)。
However, nothing happens.然而,什么也没有发生。 Have I forgotten any configurations or is it necessary to run them otherwise?我是否忘记了任何配置,或者是否有必要以其他方式运行它们?

When I'm trying to start the function directly in Visual Studio Code I'm just getting this: it gets stuck and nothing happens anymore until I stop it... message in the Terminal当我尝试直接在 Visual Studio Code 中启动该函数时,我只是得到了这个:它卡住了,直到我停止它之前什么都没有发生......终端中的消息

Thanks for your help!谢谢你的帮助!

A ServiceBusTrigger needs a Service Bus connection string of the form ServiceBusTrigger需要以下形式的服务总线连接字符串

Endpoint=sb:// ... SharedAccessKeyName ... SharedAccessKey

if using shared access keys to connect.如果使用共享访问密钥进行连接。 MyConnectionString is the connection to storage for storing the blob. MyConnectionString是用于存储 blob 的存储连接。

You can see the Service Bus connection string in the Azure python example .您可以在Azure python 示例中看到服务总线连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么这个 python function 没有在 while 循环中执行两次? - Why doesn't this python function get executed twice in a while loop? 内部while循环没有被执行 - Inner while loop doesn't get executed “process.currentDirectoryPath()”函数没有改变路径,我的python文件没有通过swift代码执行 - “process.currentDirectoryPath()” function is not changing the path and my python file doesn't get executed through swift code 当我单击“更改”按钮时,函数“ changeUsername”没有执行吗? - When I click the “Change” button, the function “changeUsername” doesn't get executed? 为什么调用Python时不执行包装函数? - Why doesn't wrap function in Python get executed when I call it? Python MySQL INSERT查询未执行 - Python MySQL INSERT query doesn't get executed Onclick 和 Listen 之外的代码不会被执行 - Code beyond the Onclick and Listen doesn't get executed Python 3.4 asyncio任务没有完全执行 - Python 3.4 asyncio task doesn't get fully executed Azure function 运行时集成不起作用 - Azure function runtime integration doesn't work 使用 function 无法为 tkinter window 生成菜单,但如果在 python 控制台上执行这些步骤,则工作正常 - Generating a menu for a tkinter window doesn’t work using a function but works just fine if the steps are executed on a python console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM