Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Azure Function Timer Trigger works for seconds but not minutes

Open xzf0587 opened this issue 1 year ago • 7 comments

I tried to create an azure function for timer. (Using Teams Toolkit extension in VS Code to create a default template app Bot -> Chat Notification Message -> Timer Trigger). And I found it works fine with "schedule": "*/30 * * * * *" but failed to trigger if I update the schedule to schedule": "* */2 * * * *". Any suggestion is welcomed for the problem. Thanks. Here is the bicep for resource deployment.

@maxLength(20)
@minLength(4)
@description('Used to generate names for all resources in this file')
param resourceBaseName string

param functionAppSKU string

@maxLength(42)
param botDisplayName string

param serverfarmsName string = resourceBaseName
param functionAppName string = resourceBaseName
param identityName string = resourceBaseName
param location string = resourceGroup().location

resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
  location: location
  name: identityName
}

// Compute resources for your Web App
resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
  kind: 'functionapp'
  location: location
  name: serverfarmsName
  sku: {
    name: functionAppSKU
  }
  properties: {}
}

// Azure Function that host your app
resource functionApp 'Microsoft.Web/sites@2021-02-01' = {
  kind: 'functionapp'
  location: location
  name: functionAppName
  properties: {
    serverFarmId: serverfarm.id
    httpsOnly: true
    siteConfig: {
      alwaysOn: true
      appSettings: [
        {
          name: 'FUNCTIONS_EXTENSION_VERSION'
          value: '~4' // Use Azure Functions runtime v4
        }
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'node' // Set runtime to NodeJS
        }
        {
          name: 'WEBSITE_RUN_FROM_PACKAGE'
          value: '1' // Run Azure Functions from a package file
        }
        {
          name: 'WEBSITE_NODE_DEFAULT_VERSION'
          value: '~18' // Set NodeJS version to 18.x
        }
        {
          name: 'BOT_ID'
          value: identity.properties.clientId
        }
        {
          name: 'BOT_TENANT_ID'
          value: identity.properties.tenantId
        }
        {
          name: 'BOT_TYPE'
          value: 'UserAssignedMsi'
        }
        {
          name: 'RUNNING_ON_AZURE'
          value: '1'
        }
        {
          name: 'SCM_ZIPDEPLOY_DONOT_PRESERVE_FILETIME'
          value: '1' // Zipdeploy files will always be updated. Detail: https://aka.ms/teamsfx-zipdeploy-donot-preserve-filetime
        }
      ]
      ftpsState: 'FtpsOnly'
    }
  }
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${identity.id}': {}
    }
  }
}

// Register your web service as a bot with the Bot Framework
module azureBotRegistration './botRegistration/azurebot.bicep' = {
  name: 'Azure-Bot-registration'
  params: {
    resourceBaseName: resourceBaseName
    identityClientId: identity.properties.clientId
    identityResourceId: identity.id
    identityTenantId: identity.properties.tenantId
    botAppDomain: functionApp.properties.defaultHostName
    botDisplayName: botDisplayName
  }
}

output BOT_DOMAIN string = functionApp.properties.defaultHostName
output BOT_AZURE_FUNCTION_APP_RESOURCE_ID string = functionApp.id
output BOT_FUNCTION_ENDPOINT string = 'https://${functionApp.properties.defaultHostName}'
output BOT_ID string = identity.properties.clientId
output BOT_TENANT_ID string = identity.properties.tenantId

xzf0587 avatar Oct 12 '24 07:10 xzf0587

I got same issue when i use TTK to create project. I set schedule: 0 0 1 * * *, fired on every morning 1 A.M. , Also not triggered. It did work in local debug session. But when I provision into Azure env, It didn't fire.

ayachensiyuan avatar Oct 12 '24 07:10 ayachensiyuan

Hi @xzf0587 Thanks for reporting will check and update.

bhagyshricompany avatar Oct 15 '24 12:10 bhagyshricompany

Hi @xzf0587 I checked and found its working.locally as well as portal also.can you check it again.Image Image

bhagyshricompany avatar Oct 15 '24 12:10 bhagyshricompany

@bhagyshricompany Thanks for your reply. The timer works fine in our old version which uses storage account for Azure function. Recently, we updated the project by using SWA for Azure function and the timer does not work. Does the different storages impact the timer?

xzf0587 avatar Oct 16 '24 05:10 xzf0587

Hi @xzf0587 I checked and found its working.locally as well as portal also.can you check it again.Image Image

I think you don't enable the RUN_FROM_PACKAGE feature because you don't have this warning bar in the top of the test page.

And here is my test result and snapshot

Image

Siglud avatar Oct 17 '24 08:10 Siglud

@kshyju please comment and validate .

bhagyshricompany avatar Oct 17 '24 12:10 bhagyshricompany

Hi @bhagyshricompany @kshyju, is there any update for this issue?

xzf0587 avatar Oct 25 '24 05:10 xzf0587

Hello @xzf0587 I found there is no issue trying it from local and as well as portal , please validate the same .

JAdluri avatar Jan 21 '25 01:01 JAdluri

This seems to be unresolved issue. When deployed via Microsoft 365 Agents Toolkit as a bot solution, Timer Triggered functions with schedule set other then seconds are not triggered at all.

Using template:

  1. Doesnt work { "bindings": [ { "name": "myTimer", "type": "timerTrigger", "direction": "in", "schedule": "* */5 * * * *" } ], "scriptFile": "../dist/src/timerTrigger.js" }

  2. Does work { "bindings": [ { "name": "myTimer", "type": "timerTrigger", "direction": "in", "schedule": "*/30 * * * * *" } ], "scriptFile": "../dist/src/timerTrigger.js" }

Mesicni avatar Jul 29 '25 14:07 Mesicni