gpt4 book ai didi

python-3.x - 我的 Python V2 Azure Function 未显示在我的 Azure 门户中

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

我正在尝试使用新的 Python Azure Function V2 方法,但由于某种原因,它不会显示在门户中。我在本地设置中设置了 "AzureWebJobsFeatureFlags": "EnableWorkerIndexing"并且启用了源代码管理,因此我通过 Github 进行部署

我的文件结构:

azure_app
- monitoring_weekly
- function_app.py
- file1.py
- file2.py
- file3.py
- file4.py
- file5.py
- host.json
- requirements.txt

Function_app.py

import azure.functions as func
import os
import datetime
import logging
import sys
import importlib.util

# Azure function timer. To alter timer cadence see function.json file
app = func.FunctionApp()

@app.function_name(name="monitoring_weekly")
@app.schedule(schedule="0 5 * * 1",
arg_name="mytimer",
run_on_startup=True,
use_monitor=True)

def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()

if mytimer.past_due:
logging.info('The timer is past due!')

logging.info('Python timer trigger function ran at %s', utc_timestamp)


def run_script(script_name):
script_path = os.path.join(os.path.dirname(__file__), f'{script_name}')

s = importlib.util.spec_from_file_location(script_name, script_path)
m = importlib.util.module_from_spec(s)
sys.modules[s.name] = m
s.loader.exec_module(m)


def batch_execution(file_list):

exceptions = [] #store errors

for file in file_list:
try:
run_script(file)
except Exception as e:
exceptions.append(e)
else:
print('Success')

return exceptions

#list of scripts running in function, if adding new script add to list.
file_list = ['file1.py',
'file2.py',
'file3.py',
'file4.py',
'file5.py']

batch_execution(file_list)

主机.json

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

需求.txt

azure-functions
sqlalchemy
snowflake-sqlalchemy
snowflake-connector-python
sparkpost
tabulate
pandas


runtime version: 4.24.4.4

enter image description here

最佳答案

我通过使用您的代码创建 Python v2 函数并将其部署到 Azure,在我的环境中重现了您的要求。

文件夹结构:

enter image description here

  • 引用MSDOC Python V1 和 V2 之间文件夹结构的差异:

enter image description here

本地响应:

enter image description here

  • Azure Function=>设置=>环境变量(或)配置中的应用程序设置:

enter image description here

我的 GitHub 工作流程,使用 GitHub 操作将 python v2 函数部署到 Azure:

name: Build and deploy Python project to Azure Function App - <webapp_name>

on:
push:
branches:
- main
workflow_dispatch:

env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
PYTHON_VERSION: '3.11'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Python version
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt

# Optional: Add step to run tests here

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: python-app
path: .

- name: 'Deploy to Azure Functions'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: '<webapp_name>'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_C0XXXXXXXXXXX}}
scm-do-build-during-deployment: true
enable-oryx-build: true

已成功部署函数应用:

enter image description here

门户:

enter image description here

enter image description here

门户响应:

enter image description here

关于python-3.x - 我的 Python V2 Azure Function 未显示在我的 Azure 门户中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77138625/

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