gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:14:27 27 4
gpt4 key购买 nike

尝试搜索 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 时注销看起来像

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\....\....>

我不知道它是否相关,但这是我在 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"
}
}

最佳答案

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

使用下面的 AzCLI 命令更新上述应用设置。

az functionapp config appsettings set --name <functionappname> --resource-group <xxxxRG> --settings WEBSITE_RUN_FROM_PACKAGE=1

enter image description here

您可以查看这个MSDoc有关功能应用设置配置的更多信息。

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

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

关于python - 发布Azure函数(模型v2)不设置触发器(函数)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76412079/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com