Azure / Azure-Functions

1.11k stars 196 forks source link

Azure Function Timer Trigger works for seconds but not minutes #2551

Open xzf0587 opened 1 week ago

xzf0587 commented 1 week ago

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
ayachensiyuan commented 1 week ago

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.

bhagyshricompany commented 5 days ago

Hi @xzf0587 Thanks for reporting will check and update.

bhagyshricompany commented 5 days ago

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

xzf0587 commented 5 days ago

@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?

Siglud commented 3 days ago

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

bhagyshricompany commented 3 days ago

@kshyju please comment .