skip to Main Content

I have an Azure Function called POEditorTranslations with TimeTrigger set to:

* */10 * * * *

First it was public static async Task POEditorTranslations….which made several requests to external APIs which were awaited.
I noteiced then it was being executed over and over again not respecting the interval above of only running each 10th minute.

So I remade it as a very basic non async function instead to only log (as in code below), but still it runs over and over again?!

Function looks like this:

 [FunctionName("POEditorTranslations")]
    public static void POEditorTranslations([TimerTrigger("%POEditorSchedule%")] TimerInfo myTimer, ILogger log, Microsoft.Azure.WebJobs.ExecutionContext context) //https://arminreiter.com/2017/02/azure-functions-time-trigger-cron-cheat-sheet/
    {
        IConfigurationRoot config = new ConfigurationBuilder()
                    .SetBasePath(context.FunctionAppDirectory)
                    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                    .AddEnvironmentVariables()
                    .Build();

        log.LogInformation($"POEditorTranslations TESTING function executed at: {DateTime.Now}, POEditorSchedule: {config.GetValue<string>("POEditorSchedule")}");

    }

So it supposed to be running every 10th minute, but it runs over and over again?!
Immediately after it have been executed it starts over again.

Note: locally running it in my Visual Studio it works, but then I have a local.settings.json file which is not present in Azure.

Still as you can see I log the value of configuration key "POEditorSchedule" and it looks correct to me.

What am I doing wrong?

Log below showing alot of these lines that it starts all over again:

2023-08-24T08:30:00Z   [Verbose]   Timer for 'POEditorTranslations' started with interval '00:00:00.8937384'.

2023-08-24T08:30:01Z [Information] Executing ‘POEditorTranslations’ (Reason=’Timer fired at 2023-08-24T08:30:00.9949394+00:00′, Id=7a0544f4-4a28-44a4-a379-2a441edb0d82)

2023-08-24T08:30:01Z [Information] POEditorTranslations TESTING function executed at: 8/24/2023 8:30:00 AM, POEditorSchedule: * */10 * * * *

2023-08-24T08:30:01Z [Information] Executed ‘POEditorTranslations’ (Succeeded, Id=7a0544f4-4a28-44a4-a379-2a441edb0d82, Duration=1ms)

2023-08-24T08:30:01Z [Verbose] Function ‘POEditorTranslations’ updated status: Last=’2023-08-24T08:30:01.0000000+00:00′, Next=’2023-08-24T08:30:02.0000000+00:00′, LastUpdated=’2023-08-24T08:30:01.0000000+00:00′

2023-08-24T08:30:01Z [Verbose] Timer for ‘POEditorTranslations’ started with interval ’00:00:00.9871280′.

2023-08-24T08:30:02Z [Information] Executing ‘POEditorTranslations’ (Reason=’Timer fired at 2023-08-24T08:30:01.9988546+00:00′, Id=003f08fc-92de-4509-8fc3-fe97a0813346)

2023-08-24T08:30:02Z [Information] POEditorTranslations TESTING function executed at: 8/24/2023 8:30:01 AM, POEditorSchedule: * */10 * * * *

2023-08-24T08:30:02Z [Information] Executed ‘POEditorTranslations’ (Succeeded, Id=003f08fc-92de-4509-8fc3-fe97a0813346, Duration=1ms)

2023-08-24T08:30:02Z [Verbose] Function ‘POEditorTranslations’ updated status: Last=’2023-08-24T08:30:02.0000000+00:00′, Next=’2023-08-24T08:30:03.0000000+00:00′, LastUpdated=’2023-08-24T08:30:02.0000000+00:00′

UPDATE

I got answer about using Environment variables instead of Configuration in Azure portal – but I do not have such menu item:

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    It looks like there is a problem to read configuration key properly like this:

    POEditorTranslations([TimerTrigger("%POEditorSchedule%")]
    

    When I hardcode it to:

    POEditorTranslations([TimerTrigger("* */10 * * * *")]
    

    it seem to work.

    I have double checked key and value and proof is also that it is render it correct when I do the logging as you could see in my example.

    Not sure how to go forward as I would like to not have it hardcoded, but for now it is ok.


  2. I have reproduced the issue at my environment but after updating the Cron expression to 0 */10 * * * * my function started working as expected in every 10 minutes

    Code:

    [FunctionName("POEditorTranslations")]
        public void Run([TimerTrigger("%POEditorSchedule%")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"POEditorTranslations TESTING function executed at: {DateTime.Now}");
        }
    

    While running locally-

    local.settings

    {
        "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "POEditorSchedule": "0 */10 * * * *"
      }
    }
    

    Local Output:

    enter image description here

    After deployment I have added POEditorSchedule to app setting-

    enter image description here

    Output:

    enter image description here

    1st trigger-

    enter image description here

    2nd trigger-

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search