Azure C#.NET计时器功能未按计划运行或手动运行

问题描述

我有一个带有计时器触发器的Azure函数。时间表为"*/6 * * * *"(每六分钟运行一次)。我无法手动运行它,并且不会自动启动。以下是我的function.json

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.31","configurationSource": "attributes","bindings": [
    {
      "type": "timerTrigger","schedule": "%TimerTriggerPeriod%","useMonitor": true,"runOnStartup": false,"name": "myTimer"
    }
  ],"disabled": false,"scriptFile": "../bin/AccessChangeMonitoring.dll","entryPoint": "Microsoft.IT.Security.AccessChangeMonitoring.AccessChangeMonitoring.InitiateChangeMonitoring"
}

%TimerTriggerPeriod%在我的local.settings.json文件("TimerTriggerPeriod": "0 */6 * * * *")中定义。查看仪表板上的“应用程序功能计数”度量标准显示,它表明我的功能已被执行 0次

enter image description here

下面是我的host.json

    {
      "version": "2.0","logging": {
        "applicationInsights": {
          "samplingExcludedTypes": "Request","samplingSettings": {
          

  "isEnabled": true
      }
    }
  },"functionTimeout": "00:07:00"
}

下面是功能代码:

[FunctionName("InitiateChangeMonitoring")]
public static async Task InitiateChangeMonitoring([TimerTrigger("%TimerTriggerPeriod%")] TimerInfo myTimer,ILogger log)
{
    log.LogInformation("Change Monitoring started.");

    // Reset the listing of app ids we need to retrieve delta role assignments for
    oneAuthZAppIds = new List<string>();
    await GetOneAuthZAppIdsAsync();

    // Create the necessary Cosmos DB infastructure
    await CreateDatabaseAsync();
    await CreateContainerAsync();
    await CreateDeltaAPICallDatabaseAsync();
    await CreateDeltaAPICallContainerAsync();

    await CreateManagerMappingDatabaseAsync();
    await CreateManagerMappingContainerAsync();

    // Compute the authentication token needed to access the PAP Service API
    log.LogInformation("\nRetrieve PAPServiceAPIToken");
    string PAPServiceAPIToken = await GetTokenAsync(Environment.GetEnvironmentVariable("OneAuthZAppUri"),Environment.GetEnvironmentVariable("OneAuthZAppId"),PAPAuthenticationSecret);
    log.LogInformation("PAPServiceAPIToken = " + PAPServiceAPIToken);

    string GraphAPIAuthenticationToken = await GetTokenAsync(Environment.GetEnvironmentVariable("GraphAppUri"),Environment.GetEnvironmentVariable("GraphClientId"),graphKey);
    log.LogInformation("graphAPIAuthenticationToken = " + GraphAPIAuthenticationToken);

    await runChangeMonitoringSystemAsync(PAPServiceAPIToken);
}

解决方法

首先,我注意到您指定您正在使用local.settings.json来保存环境变量,并同时在天蓝色上显示指标。

所以,我认为为什么无法触发您的azure函数的第一个问题是因为您没有在azure上设置环境变量。

您应该在此位置设置而不是local.settings.json :(因为将azure函数部署到azure时,它将永远不会从local.settings.json中获取环境变量。)

enter image description here

(不要忘记保存所做的编辑。)

第二,如Ivan所说,您的cron格式错误。时间触发的格式应为以下格式:

{second} {minute} {hour} {day} {month} {day of week}

让我知道您是否可以解决这个问题。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...