Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function timer trigger not firing

I recently changed my Azure Functions project to have .Net 6 Isolated runtime, but now when I deploy it my timer triggers are never firing. I've browsed through as many similar posts but nothing I've changed has seem to fix it. It runs fine locally, just not once it's deployed.

Program.cs

using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .Build();

host.Run();

Function's File

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace MyProj.AzureFunctions
{
    public class Functions
    {
        private readonly ILogger _logger;

        public Functions(ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<Functions>();
        }

        [Function("Health")]
        public void Health([TimerTrigger("* * * * *")] MyInfo myTimer, ILogger log)
        {
            log.LogInformation("Health Check Successful.");
        }
    }

    public class MyInfo
    {
        public MyScheduleStatus ScheduleStatus { get; set; }

        public bool IsPastDue { get; set; }
    }

    public class MyScheduleStatus
    {
        public DateTime Last { get; set; }

        public DateTime Next { get; set; }

        public DateTime LastUpdated { get; set; }
    }
}

host.json

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingExcludedTypes": "Request",
            "samplingSettings": {
                "isEnabled": true
            }
        }
    }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

.csproj configuration

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/>
  </ItemGroup>
</Project>

Azure Functions Settings

Settings

I've tried to look at the log files in /LogFiles/Application/Functions/Host but couldn't find any clues. The file just has this bit repeating a few hundred times

2023-02-28T19:48:29.700 [Information] Host Status: {
  "id": "devfunctions",
  "state": "Running",
  "version": "4.15.2.20177",
  "versionDetails": "4.15.2+28e9550320b13137f4eaf16483ebcdb630699506",
  "platformVersion": "99.0.10.793",
  "instanceId": "de79fd99bf2007cea7cba17a54c929b84f3dafad58d9cd5c0c16eccc0cd59790",
  "computerName": "10-30-3-159",
  "processUptime": 4170653,
  "functionAppContentEditingState": "Unknown"
}

but can't find any proof that my function is ever firing.

like image 681
Dillon Drobena Avatar asked Sep 01 '26 17:09

Dillon Drobena


1 Answers

Looking at your code, you seem to have run into the same issue I had a while back.

It seems that the VS template creates a five-element cron statement by default: * * * * * whilst you actually need six (NCRONTAB) for the function to correctly execute: * * * * * * ({second} {minute} {hour} {day} {month} {day-of-week})

It's an odd bug, but you can check out more information on Timmer triggers and possible NCRONTAB statements here.

like image 118
akseli Avatar answered Sep 04 '26 11:09

akseli