我有一个使用azure持久功能的应用程序,它在本地运行得很好,但是当我容器化这个应用程序并运行我的图像时,我收到此错误:无法解析名为“AzureWebJobsStorage”的Azure存储连接。
这是我测试过的:
"extensions": {
"durableTask": {
"hubName": "MyTaskHub",
"storageProvider": {
"connectionStringName": "AzureWebJobsStorage"
}
}
},
但是没有任何效果:( 非常感谢您的帮助,谢谢!
当我尝试运行容器化Python Azure Durable函数时,我遇到了同样的错误。
AzureWebJobsStorage
的环境变量传递给 docker run
命令。docker run -p 8080:80 -it -e AzureWebJobsStorage="<Storage_connection_string>" <Image_name>:tag
或将
Storage_account
设置为 ARG 并将其作为 Docker 文件中的环境变量传递。
Dockerfile:
FROM mcr.microsoft.com/azure-functions/python:4-python3.11
ARG STORAGE_ACCOUNT
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
AzureWebJobsStorage=$STORAGE_ACCOUNT
COPY requirements.txt /
RUN pip install -r /requirements.txt
COPY . /home/site/wwwroot
1. docker build --build-arg STORAGE_ACCOUNT='<storage_connection_string>' -t <Image_name> .
2. docker run -p 8080:80 <Image_name>
使用 docker 创建了一个 python 持久函数:
func init --docker
func new
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
(.venv) C:\Users\uname\pydf>docker run -p 8080:80 -it -e AzureWebJobsStorage="<Storage_connection_string>" pravallikakv/pydf
info: Host.Triggers.DurableTask[0]
Using the default storage provider: AzureStorage.
info: Host.Triggers.Warmup[0]
Initializing Warmup Extension.
info: Host.Triggers.DurableTask[0]
Durable extension configuration loaded: {"httpSettings":{"defaultAsyncRequestSleepTimeMilliseconds":30000},"hubName":"TestHubName","storageProvider":{"connectionName":null,"connectionStringName":null,"controlQueueBatchSize":32,"partitionCount":4,"controlQueueBufferThreshold":256,"controlQueueVisibilityTimeout":"00:05:00","workItemQueueVisibilityTimeout":"00:05:00","trackingStoreConnectionName":null,"trackingStoreConnectionStringName":null,"trackingStoreNamePrefix":null,"fetchLargeMessagesAutomatically":true,"maxQueuePollingInterval":"00:00:30","useLegacyPartitionManagement":false,"useTablePartitionManagement":false},"tracing":{"traceInputsAndOutputs":false,"allowVerboseLinuxTelemetry":false,"traceReplayEvents":false,"distributedTracingEnabled":false,"distributedTracingProtocol":"HttpCorrelationProtocol","version":"V1"},"notifications":{"eventGrid":null},"maxConcurrentActivityFunctions":80,"maxConcurrentOrchestratorFunctions":80,"localRpcEndpointEnabled":null,"maxEntityOperationBatchSize":5000,"extendedSessionsEnabled":false,"extendedSessionIdleTimeoutInSeconds":30,"maxOrchestrationActions":100000,"overridableExistingInstanceStates":"NonRunningStates","entityMessageReorderWindowInMinutes":30,"useGracefulShutdown":false,"rollbackEntityOperationsOnExceptions":true,"throwStatusExceptionsOnRaiseEvent":null,"useAppLease":true,"storeInputsInOrchestrationHistory":false,"appLeaseOptions":{"renewInterval":"00:00:25","acquireInterval":"00:05:00","leaseInterval":"00:01:00"}}. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0.
info: Host.Triggers.DurableTask[0]
Opened local http RPC endpoint: http://127.0.0.1:17071/durabletask/. InstanceId: . Function: . HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 0.
info: Host.Startup[503]
Initializing Host. OperationId: '170705c0-6b98-4333-a11c-45e3a13ce129'.
info: Host.Startup[504]
Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=170705c0-6b98-4333-a11c-45e3a13ce129
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
LoggerFilterOptions
{
"MinLevel": "None",
"Rules": [
{
"ProviderName": null,
"CategoryName": null,
"LogLevel": null,
"Filter": "<AddFilter>b__0"
},
{
"ProviderName": null,
"CategoryName": "Host.Function.ToolingConsoleLog",
"LogLevel": "Information",
"Filter": null
},
{
"ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
"CategoryName": null,
"LogLevel": "None",
"Filter": null
},
{
"ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
"CategoryName": null,
"LogLevel": null,
"Filter": "<AddFilter>b__0"
}
]
}
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
LanguageWorkerOptions
{
"WorkerConfigs": [
{
"Description": {
"Language": "python",
"DefaultRuntimeName": null,
"DefaultRuntimeVersion": "3.11",
"SupportedArchitectures": [
"X64",
"X86",
"Arm64"
],
"SupportedOperatingSystems": [
"LINUX",
"OSX",
"WINDOWS"
],
"SupportedRuntimeVersions": [
"3.7",
"3.8",
"3.9",
"3.10",
"3.11"
],
"SanitizeRuntimeVersionRegex": null,
"WorkerIndexing": "true",
"Extensions": [
".py"
],
"UseStdErrorStreamForErrorsOnly": false,
"DefaultExecutablePath": "python",
"DefaultWorkerPath": "/azure-functions-host/workers/python/3.11/LINUX/X64/worker.py",
"WorkerDirectory": "/azure-functions-host/workers/python",
"Arguments": [],
"WorkerArguments": null
},
"Arguments": {
"ExecutablePath": "python",
"ExecutableArguments": [],
"WorkerPath": "/azure-functions-host/workers/python/3.11/LINUX/X64/worker.py",
"WorkerArguments": []
},
"CountOptions": {
"SetProcessCountToNumberOfCpuCores": false,
"ProcessCount": 1,
"MaxProcessCount": 10,
"ProcessStartupInterval": "00:00:10",
"ProcessStartupTimeout": "00:01:00",
"InitializationTimeout": "00:00:10",
"EnvironmentReloadTimeout": "00:00:30",
"ProcessRestartInterval": "00:00:10",
"ProcessShutdownTimeout": "00:00:10"
}
}
]
}
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
ConcurrencyOptions
{
"DynamicConcurrencyEnabled": false,
"MaximumFunctionConcurrency": 500,
"CPUThreshold": 0.8,
"SnapshotPersistenceEnabled": true
}
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
FunctionResultAggregatorOptions
{
"BatchSize": 1000,
"FlushTimeout": "00:00:30",
"IsEnabled": true
}
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
SingletonOptions
{
"LockPeriod": "00:00:15",
"ListenerLockPeriod": "00:01:00",
"LockAcquisitionTimeout": "10675199.02:48:05.4775807",
"LockAcquisitionPollingInterval": "00:00:05",
"ListenerLockRecoveryPollingInterval": "00:01:00"
}
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
ScaleOptions
{
"ScaleMetricsMaxAge": "00:02:00",
"ScaleMetricsSampleInterval": "00:00:10",
"MetricsPurgeEnabled": true,
"IsTargetScalingEnabled": true,
"IsRuntimeScalingEnabled": false
}
info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
Starting JobHost
info: Host.Startup[401]
Starting Host (HostId=907ed61a64ca-2137340777, InstanceId=69317c69-6d0f-4c7d-b241-725fc03fe0fb, Version=4.31.1.1, ProcessId=9, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
info: Host.Startup[314]
Loading functions metadata
info: Host.Startup[326]
Reading functions metadata (Custom)
info: Host.Startup[327]
1 functions found (Custom)
info: Host.Startup[315]
3 functions loaded
info: Host.Startup[0]
Generating 3 job function(s)
info: Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcFunctionInvocationDispatcher[0]
Worker process started and initialized.
info: Host.Startup[0]
Found the following functions:
Host.Functions.DurableFunctionsHttpStart
Host.Functions.DurableFunctionsOrchestrator
Host.Functions.Hello
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
HttpOptions
{
"DynamicThrottlesEnabled": false,
"EnableChunkedRequestBinding": false,
"MaxConcurrentRequests": -1,
"MaxOutstandingRequests": -1,
"RoutePrefix": "api"
}
info: Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostHttpRoutesManager[0]
Initializing function HTTP routes
Mapped function route 'api/orchestrators/{functionName}' [post,get] to 'DurableFunctionsHttpStart'
info: Host.Startup[412]
Host initialized (229ms)
info: Host.Triggers.DurableTask[0]
Starting task hub worker. Extension GUID d96ae2fc-98f4-4254-a8cd-e4a60434cb7b. InstanceId: . Function: . HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 1.
info: Host.Triggers.DurableTask[0]
Task hub worker started. Latency: 00:00:01.7470632. Extension GUID d96ae2fc-98f4-4254-a8cd-e4a60434cb7b. InstanceId: . Function: . HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 2.
info: Host.Startup[413]
Host started (2055ms)
info: Host.Startup[0]
Job host started
Hosting environment: Production
Content root path: /azure-functions-host
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
info: Host.General[337]
Host lock lease acquired by instance ID '0000000000000000000000001F8FC5BA'.
参考资料:
https://medium.com/@cmendibl3/run-a-durable-azure-function-in-a-container-d0844fec765a