Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xzf0587 opened this issue Oct 12, 2024 · 7 comments
Open

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

xzf0587 opened this issue Oct 12, 2024 · 7 comments
Assignees
Labels

Comments

@xzf0587
Copy link

xzf0587 commented Oct 12, 2024

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 xzf0587 added the bug label Oct 12, 2024
@ayachensiyuan
Copy link

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 bhagyshricompany self-assigned this Oct 15, 2024
@bhagyshricompany
Copy link

Hi @xzf0587 Thanks for reporting will check and update.

@bhagyshricompany
Copy link

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

@xzf0587
Copy link
Author

xzf0587 commented Oct 16, 2024

@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
Copy link

Siglud commented Oct 17, 2024

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
Copy link

bhagyshricompany commented Oct 17, 2024

@kshyju please comment and validate .

@xzf0587
Copy link
Author

xzf0587 commented Oct 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants