发布 Azure 函数(模型 v2)不设置触发器(函数)?

huangapple go评论88阅读模式
英文:

Publish Azure functions (model v2) don't set triggers (functions)?

问题

I have translated the provided content for you. Here is the translated text:

尝试搜索Google/Bing聊天/Stack并没有找到解决我的问题的方法。

我有以下环境:

IDE:PyCharm,CLI:Microsoft az/func(正常运行)。使用 func init 定义本地环境。在Azure函数中创建了该函数。local.settings.json 中的设置与在线环境相同。应用程序中的文件已经发布。整个项目的虚拟环境(venv)相同,但我在文件夹中放了一个单独的 requirements.txt

使用 func start 本地运行函数正常。

但是使用 <function folder>\func azure functionapp publish ... 发布的函数没有触发器/函数。

我的函数如下所示:

import azure.functions as func
import logging

from py_pdf import PdfOcrReader

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.function_name(name="healthcheck")
@app.route(route="healthcheck")
def healthcheck(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("Status OK", status_code=200)

@app.function_name(name="pypdf")
@app.route(route="pypdf")
def pypdf_api(req: func.HttpRequest) -> func.HttpResponse:
    file = req.files.get('file')
    if not file:
        return func.HttpResponse("No file found in the request.", status_code=400)

    # process file
    pdf_obj = PdfOcrReader(file)

    json_out = {
        "pdf_text": pdf_obj.pdf_text,
        "ocr_text": pdf_obj.ocr_computer_vision()
    }
    json_out.update(pdf_obj.metadata)

    return func.HttpResponse(
        str(json_out), status_code=200
    )

host.json 如下:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

P.S:func publish 时的日志如下:

警告:以 'root' 用户身份运行 pip 可能导致权限损坏和与系统包管理器的冲突行为。建议使用虚拟环境:https://pip.pypa.io/warnings/venv
警告:您正在使用 pip 版本 21.2.4;然而,版本 23.1.2 已经可用。
您应该考虑通过 '/tmp/oryx/platforms/python/3.10.4/bin/python3.10 -m pip install --upgrade pip' 命令进行升级。
不是 vso 映像,因此不写入构建命令
准备输出...

正在将文件复制到目标目录 '/home/site/wwwroot'...
完成,耗时 0 秒。

删除现有的清单文件
正在创建清单文件...
已创建清单文件。
将 .ostype 复制到清单输出目录。

完成,耗时 8 秒。
运行发布后命令...

生成 Oryx 构建的摘要
/tmp/oryx-build.log 中不存在部署日志文件
/tmp/oryx-build.log 中的日志文件为空。无法获取构建摘要
触发循环 (预览模式已禁用)。
Linux 消耗计划在远程构建容器上有 1.5 GB 内存限制。
要检查我们的服务限制,请访问 https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale#service-limits
将工件写入 squashfs 文件
并行 mksquashfs: 使用 1 个处理器
正在 /home/site/artifacts/functionappartifact.squashfs 上创建 4.0 文件系统,块大小为 131072。

[=============================================================-] 1250/1250 100%

可导出的 Squashfs 4.0 文件系统,gzip 压缩,数据块大小 131072
        压缩的数据,压缩的元数据,压缩的片段,
        压缩的 xattrs,压缩的 ID
        已删除重复项
文件系统大小 40794.51 Kbytes(39.84 Mbytes)
        未压缩文件系统大小的 74.13%(55031.18 Kbytes)
Inode 表大小 10917 字节(10.66 Kbytes)
        未压缩 Inode 表大小的 31.05%(35154 字节)
目录表大小 9962 字节(9.73 Kbytes)
        未压缩目录表大小的 35.27%(28244 字节)
        根 (0)
为 Linux 消耗函数应用创建占位符 blob...
已找到 SCM_RUN_FROM_PACKAGE 占位符 blob scm-latest-....zip
正在上传构建内容 /home/site/artifacts/functionappartifact.squashfs 以供 Linux 消耗函数应用使用...
重置所有工作者以 ....azurewebsites.net
部署成功。deployer = Push-Deployer deploymentPath = Functions App ZipDeploy. 提取 zip 文件。远程构建。
远程构建成功!
正在同步触发器...
.... 中的函数:
(venv) PS C:\Users\civan\PycharmProjects\....\....>

我不知道是否相关,但这是我在更改 host.json 后发布时的日志流:

已连接!
2023-06-06T07:57:50Z   [详细]   收到停用主机的请求
2023-06-06T07:57:50Z   [信息]   启用 DrainMode 模式
2023-06-06T07:57:50Z   [信息]   调用已注册侦听器的 StopAsync
2023-06-06T07:57:50Z   [信息]   StopAsync 调用完成,已停用已注册侦听器
2023-06-06T07:57:50Z   [详细]   收到停用主机的请求
2023-06-06T07:58:02Z

<details>
<summary>英文:</summary>

Tried to search Google/Bing chat/Stack and didn&#39;t find a solution to my issue.

I have the following environment:

IDE: PyCharm, CLI: microsoft az/func (running fine). Defined local with `func init`. Created the function in azure function. The settings from local.settings.json are the same with one online. The files from application are current published. The venv is the same for entire project but i put a separate requirements.txt in folder.

The function locally is running nicely with `func start` 

But the published function with `&lt;function folder&gt;\func azure functionapp publish ...` don&#39;t have triggers / functions.

My functions is like this:

import azure.functions as func
import logging

from py_pdf import PdfOcrReader

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.function_name(name="healthcheck")
@app.route(route="healthcheck")
def healthcheck(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse("Status OK", status_code=200)

@app.function_name(name="pypdf")
@app.route(route="pypdf")
def pypdf_api(req: func.HttpRequest) -> func.HttpResponse:
file = req.files.get('file')
if not file:
return func.HttpResponse("No file found in the request.", status_code=400)

# process file
pdf_obj = PdfOcrReader(file)

json_out = {
    &quot;pdf_text&quot;: pdf_obj.pdf_text,
    &quot;ocr_text&quot;: pdf_obj.ocr_computer_vision()
}
json_out.update(pdf_obj.metadata)

return func.HttpResponse(
    str(json_out), status_code=200
)
The host.json is looking like this:

{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}



P.S: The loggout when `func publish` looks like

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.4; however, version 23.1.2 is available.
You should consider upgrading via the '/tmp/oryx/platforms/python/3.10.4/bin/python3.10 -m pip install --upgrade pip' command.
Not a vso image, so not writing build commands
Preparing output...

Copying files to destination directory '/home/site/wwwroot'...
Done in 0 sec(s).

Removing existing manifest file
Creating a manifest file...
Manifest file created.
Copying .ostype to manifest output directory.

Done in 8 sec(s).
Running post deployment command(s)...

Generating summary of Oryx build
Deployment Log file does not exist in /tmp/oryx-build.log
The logfile at /tmp/oryx-build.log is empty. Unable to fetch the summary of build
Triggering recycle (preview mode disabled).
Linux Consumption plan has a 1.5 GB memory limit on a remote build container.
To check our service limit, please visit https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale#service-limits
Writing the artifacts to a squashfs file
Parallel mksquashfs: Using 1 processor
Creating 4.0 filesystem on /home/site/artifacts/functionappartifact.squashfs, block size 131072.

[=============================================================-] 1250/1250 100%

Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
compressed data, compressed metadata, compressed fragments,
compressed xattrs, compressed ids
duplicates are removed
Filesystem size 40794.51 Kbytes (39.84 Mbytes)
74.13% of uncompressed filesystem size (55031.18 Kbytes)
Inode table size 10917 bytes (10.66 Kbytes)
31.05% of uncompressed inode table size (35154 bytes)
Directory table size 9962 bytes (9.73 Kbytes)
35.27% of uncompressed directory table size (28244 bytes)
root (0)
Creating placeholder blob for linux consumption function app...
SCM_RUN_FROM_PACKAGE placeholder blob scm-latest-....zip located
Uploading built content /home/site/artifacts/functionappartifact.squashfs for linux consumption function app...
Resetting all workers for ....azurewebsites.net
Deployment successful. deployer = Push-Deployer deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
Remote build succeeded!
Syncing triggers...
Functions in ....:
(venv) PS C:\Users\civan\PycharmProjects........>

I don&#39;t know if it relevant, but this is a logstream when I published a change in host.json:

Connected!
2023-06-06T07:57:50Z [Verbose] Received request to drain the host
2023-06-06T07:57:50Z [Information] DrainMode mode enabled
2023-06-06T07:57:50Z [Information] Calling StopAsync on the registered listeners
2023-06-06T07:57:50Z [Information] Call to StopAsync complete, registered listeners are now stopped
2023-06-06T07:57:50Z [Verbose] Received request to drain the host
2023-06-06T07:58:02Z [Information] File change of type 'Changed' detected for 'C:\Users\civan\PycharmProjects......\host.json'
2023-06-06T07:58:02Z [Information] Host configuration has changed. Signaling restart
2023-06-06T07:58:02Z [Information] File change of type 'Changed' detected for 'C:\Users\civan\PycharmProjects......\host.json'
2023-06-06T07:58:02Z [Information] Host configuration has changed. Signaling restart
2023-06-06T07:58:10Z [Information] Host lock lease acquired by instance ID '00000000000000000000000021706BBA'.
2023-06-06T07:58:10Z [Verbose] Initiating background SyncTriggers operation
2023-06-06T07:58:10Z [Information] Loading functions metadata
2023-06-06T07:58:10Z [Information] Reading functions metadata
2023-06-06T07:58:10Z [Information] 1 functions found
2023-06-06T07:58:10Z [Information] 0 functions loaded
2023-06-06T07:58:10Z [Information] Loading functions metadata
2023-06-06T07:58:10Z [Information] Reading functions metadata
2023-06-06T07:58:10Z [Information] 1 functions found
2023-06-06T07:58:10Z [Information] 0 functions loaded
2023-06-06T07:58:14Z [Verbose] Received request to drain the host
2023-06-06T07:58:14Z [Information] DrainMode mode enabled
2023-06-06T07:58:14Z [Information] Calling StopAsync on the registered listeners
2023-06-06T07:58:14Z [Information] Call to StopAsync complete, registered listeners are now stopped
2023-06-06T07:59:09Z [Verbose] Received request to drain the host
2023-06-06T07:59:09Z [Information] DrainMode mode enabled
2023-06-06T07:59:09Z [Information] Calling StopAsync on the registered listeners
2023-06-06T07:59:09Z [Information] Call to StopAsync complete, registered listeners are now stopped
2023-06-06T07:59:09Z [Verbose] Received request to drain the host
2023-06-06T07:59:09Z [Information] DrainMode mode enabled
2023-06-06T07:59:09Z [Information] Calling StopAsync on the registered listeners
2023-06-06T07:59:09Z [Information] Call to StopAsync complete, registered listeners are now stopped
2023-06-06T07:59:54Z [Verbose] Received request to drain the host
2023-06-06T07:59:54Z [Information] DrainMode mode enabled
2023-06-06T07:59:54Z [Information] Calling StopAsync on the registered listeners
2023-06-06T07:59:54Z [Information] Call to StopAsync complete, registered listeners are now stopped
2023-06-06T08:00:26Z [Information] Host lock lease acquired by instance ID '0000000000000000000000008EA10CF8'.
2023-06-06T08:00:55Z [Information] Host Status: {
"id": "ocroperations",
"state": "Running",
"version": "4.21.3.3",
"versionDetails": "4.21.3+2e42e3beb40b89d4f5d3dd962f3a5d420d376d71",
"platformVersion": "",
"instanceId": "54108609-638216349727465766",
"computerName": "",
"processUptime": 267075,
"functionAppContentEditingState": "NotAllowed",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "4.5.0"
}
}



</details>


# 答案1
**得分**: 1

这可能是因为`WEBSITE_RUN_FROM_PACKAGE`应用设置设置不正确。这指定函数应用程序是否应从包文件或从`wwwroot`目录中的文件运行。

使用以下`AzCLI`命令来更新上述应用设置。

```bash
az functionapp config appsettings set --name &lt;functionappname&gt; --resource-group &lt;xxxxRG&gt; --settings WEBSITE_RUN_FROM_PACKAGE=1

发布 Azure 函数(模型 v2)不设置触发器(函数)?

您可以查阅此MSDoc以获取有关函数应用程序设置配置的更多信息。

此问题也可能是由部署包文件引起的。请参考此处以从包文件中运行函数。

如果问题仍然存在,请尝试创建一个新的Python触发器Azure函数,并在清除缓存后部署它。

英文:

This could be because the WEBSITE_RUN_FROM_PACKAGE app setting is incorrectly set. This specifies whether the function app should be run from a package file or from files in the wwwroot directory.

Use below AzCLI command to update the above app setting.

az functionapp config appsettings set --name &lt;functionappname&gt; --resource-group &lt;xxxxRG&gt; --settings WEBSITE_RUN_FROM_PACKAGE=1

发布 Azure 函数(模型 v2)不设置触发器(函数)?

You can check this MSDoc for more information on function app settings configuration.

This issue could also be caused by the deployment package file. Refer here to run functions from the package file.

If still the issue persists, try creating a new python trigger Azure function and deploy it after clearing the cache.

huangapple
  • 本文由 发表于 2023年6月6日 14:49:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定