Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In the following code, I use %SCHEDULE% to fetch Ncrontab string from environment variable in my azure function:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace Sample.AzureFunction
    public class TimerExample
        [FunctionName("TimerTrigger")]
        public async Task TimerRun(
            [TimerTrigger("%SCHEDULE%")] TimerInfo myTimer, ILogger log)
            log.LogInformation("C# Timer trigger function processed a request.");

Then I build it as a docker image:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
# Build requires 3.1 SDK
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet
COPY ./src /src/Sample.AzureFunction
RUN cd /src/Sample.AzureFunction && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish *.csproj --output /home/site/wwwroot
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:4-appservice
FROM mcr.microsoft.com/azure-functions/dotnet:4-slim
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
$ docker build --tag <dockerId>/sample.functionapp:develop .

When I run a cron job that repeats within 1 minute like this, that's fine:

$ docker run -p 8080:80 -it -e SCHEDULE='*/10 * * * * *' <dockerId>/sample.functionapp:develop

However, when I run a cron job that repeats in a longer timespan like this, errors occurred:

$ docker run -p 8080:80 -it -e SCHEDULE='0 */1 * * * *' <dockerId>/sample.functionapp:develop

The error says:

fail: Host.Startup[0]
      The listener for function 'TimerTriggerFunc' was unable to start.
      Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException: The listener for function 'TimerTriggerFunc' was unable to start.
       ---> System.InvalidOperationException: Could not create BlobContainerClient for ScheduleMonitor
         at Microsoft.Azure.WebJobs.Extensions.Timers.StorageScheduleMonitor.get_ContainerClient() in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Timers.Storage\StorageScheduleMonitor.cs:line 83
         at Microsoft.Azure.WebJobs.Extensions.Timers.StorageScheduleMonitor.GetStatusBlobClient(String timerName, Boolean createContainerIfNotExists) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Timers.Storage\StorageScheduleMonitor.cs:line 155
         at Microsoft.Azure.WebJobs.Extensions.Timers.StorageScheduleMonitor.GetStatusAsync(String timerName) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Timers.Storage\StorageScheduleMonitor.cs:line 94
         at Microsoft.Azure.WebJobs.Extensions.Timers.Listeners.TimerListener.StartAsync(CancellationToken cancellationToken) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions\Extensions\Timers\Listener\TimerListener.cs:line 105
         at Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener.StartAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Singleton\SingletonListener.cs:line 70
         at Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener.StartAsync(CancellationToken cancellationToken, Boolean allowRetry) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\FunctionListener.cs:line 68
         --- End of inner exception stack trace ---

The full log is:

info: Host.Triggers.Warmup[0]
      Initializing Warmup Extension.
info: Host.Startup[503]
      Initializing Host. OperationId: '5492efd6-ae3f-455e-81f7-b3d51a78ec12'.
info: Host.Startup[504]
      Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=5492efd6-ae3f-455e-81f7-b3d51a78ec12
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]
      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.JobHostService[0]
      Starting JobHost
info: Host.Startup[401]
      Starting Host (HostId=dee9d0eebc87-2137340777, InstanceId=a0f6679e-ac77-411b-9793-9b8553973900, Version=4.13.0.0, ProcessId=1, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
info: Host.Startup[314]
      Loading functions metadata
info: Host.Startup[326]
      Reading functions metadata
info: Host.Startup[327]
      1 functions found
info: Host.Startup[315]
      2 functions loaded
info: Host.Startup[0]
      Generating 2 job function(s)
info: Host.Startup[0]
      Found the following functions:
      Sample.AzureFunction.HttpExample.Run
      Sample.AzureFunction.TimerExample.Run
info: Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostHttpRoutesManager[0]
      Initializing function HTTP routes
      Mapped function route 'api/HttpExample' [get,post] to 'HttpExample'
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
      HttpOptions
        "DynamicThrottlesEnabled": false,
        "EnableChunkedRequestBinding": false,
        "MaxConcurrentRequests": -1,
        "MaxOutstandingRequests": -1,
        "RoutePrefix": "api"
info: Host.Startup[412]
      Host initialized (142ms)
fail: Host.Startup[0]
      The listener for function 'TimerTriggerFunc' was unable to start.
      Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException: The listener for function 'TimerTriggerFunc' was unable to start.
       ---> System.InvalidOperationException: Could not create BlobContainerClient for ScheduleMonitor
         at Microsoft.Azure.WebJobs.Extensions.Timers.StorageScheduleMonitor.get_ContainerClient() in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Timers.Storage\StorageScheduleMonitor.cs:line 83
         at Microsoft.Azure.WebJobs.Extensions.Timers.StorageScheduleMonitor.GetStatusBlobClient(String timerName, Boolean createContainerIfNotExists) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Timers.Storage\StorageScheduleMonitor.cs:line 155
         at Microsoft.Azure.WebJobs.Extensions.Timers.StorageScheduleMonitor.GetStatusAsync(String timerName) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Timers.Storage\StorageScheduleMonitor.cs:line 94
         at Microsoft.Azure.WebJobs.Extensions.Timers.Listeners.TimerListener.StartAsync(CancellationToken cancellationToken) in C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions\Extensions\Timers\Listener\TimerListener.cs:line 105
         at Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener.StartAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Singleton\SingletonListener.cs:line 70
         at Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener.StartAsync(CancellationToken cancellationToken, Boolean allowRetry) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\FunctionListener.cs:line 68
         --- End of inner exception stack trace ---
info: Host.Startup[413]
      Host started (175ms)
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.Startup[0]
      Retrying to start listener for function 'TimerTriggerFunc' (Attempt 1)
info: Host.Startup[0]
      Listener successfully started for function 'TimerTriggerFunc' after 1 retries.
info: Host.General[337]
      Host lock lease acquired by instance ID '000000000000000000000000C2D27438'.

Hope anyone can help, thank in advance!

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.