Azure Function默认模板无法在本地运行

时间:2019-05-15 10:18:22

标签: azure-functions

我正在尝试创建Azure Function并在本地对其进行测试。我有MSFT VS2017 + Azure开发工具。我已经使用TimerTrigger创建了Azure Function项目。我没有更改默认模板中的任何内容。

函数是:

 SELECT  
   i.IncidentID, 
   CASE WHEN CHARINDEX('asda', sa.AddressStreet) > 0 THEN 'true' else 'false' end AS 'asda' 
FROM Incident i
JOIN IncidentSubject isu ON isu.IncidentID = i.IncidentID
JOIN SubjectAddress sa ON sa.SubjectID = isu.SubjectID
WHERE i.Section <> 0 AND (i.Section & 255 <> 0)

运行时:

    [FunctionName("Function1")]
    public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
    {
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    }

,它在这里失败:

              %%%%%%
             %%%%%%
        @   %%%%%%    @
      @@   %%%%%%      @@
   @@@    %%%%%%%%%%%    @@@
 @@      %%%%%%%%%%        @@
   @@         %%%%       @@
     @@      %%%       @@
       @@    %%      @@
            %%
            %

Azure Functions Core Tools (2.7.1158 Commit hash: f2d2a2816e038165826c7409c6d10c0527e8955b)
Function Runtime Version: 2.0.12438.0
SKipping 'FUNCTIONS_CORETOOLS_ENVIRONMENT' because value is null
[5/15/2019 10:11:50 AM] Starting Rpc Initialization Service.
[5/15/2019 10:11:50 AM] Initializing RpcServer
[5/15/2019 10:11:50 AM] Building host: startup suppressed:False, configuration suppressed: False
[5/15/2019 10:11:52 AM] Initializing Host.
[5/15/2019 10:11:52 AM] Host initialization: ConsecutiveErrors=0, StartupCount=1
[5/15/2019 10:11:52 AM] LoggerFilterOptions
[5/15/2019 10:11:52 AM] {
[5/15/2019 10:11:52 AM]   "MinLevel": "None",
[5/15/2019 10:11:52 AM]   "Rules": [
[5/15/2019 10:11:52 AM]     {
[5/15/2019 10:11:52 AM]       "ProviderName": null,
[5/15/2019 10:11:52 AM]       "CategoryName": null,
[5/15/2019 10:11:52 AM]       "LogLevel": null,
[5/15/2019 10:11:52 AM]       "Filter": "<AddFilter>b__0"
[5/15/2019 10:11:52 AM]     },
[5/15/2019 10:11:52 AM]     {
[5/15/2019 10:11:52 AM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[5/15/2019 10:11:52 AM]       "CategoryName": null,
[5/15/2019 10:11:52 AM]       "LogLevel": "None",
[5/15/2019 10:11:52 AM]       "Filter": null
[5/15/2019 10:11:52 AM]     },
[5/15/2019 10:11:52 AM]     {
[5/15/2019 10:11:52 AM]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[5/15/2019 10:11:52 AM]       "CategoryName": null,
[5/15/2019 10:11:52 AM]       "LogLevel": null,
[5/15/2019 10:11:52 AM]       "Filter": "<AddFilter>b__0"
[5/15/2019 10:11:52 AM]     }
[5/15/2019 10:11:52 AM]   ]
[5/15/2019 10:11:52 AM] }
[5/15/2019 10:11:52 AM] FunctionResultAggregatorOptions
[5/15/2019 10:11:52 AM] {
[5/15/2019 10:11:52 AM]   "BatchSize": 1000,
[5/15/2019 10:11:52 AM]   "FlushTimeout": "00:00:30",
[5/15/2019 10:11:52 AM]   "IsEnabled": true
[5/15/2019 10:11:52 AM] }
[5/15/2019 10:11:52 AM] SingletonOptions
[5/15/2019 10:11:52 AM] {
[5/15/2019 10:11:52 AM]   "LockPeriod": "00:00:15",
[5/15/2019 10:11:52 AM]   "ListenerLockPeriod": "00:00:15",
[5/15/2019 10:11:52 AM]   "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[5/15/2019 10:11:52 AM]   "LockAcquisitionPollingInterval": "00:00:05",
[5/15/2019 10:11:52 AM]   "ListenerLockRecoveryPollingInterval": "00:01:00"
[5/15/2019 10:11:52 AM] }
[5/15/2019 10:11:52 AM] Starting JobHost
[5/15/2019 10:11:52 AM] Starting Host (HostId=, InstanceId=79b21f7e-8904-41d9-9339-df547871c510, Version=2.0.12438.0, ProcessId=10380, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=)
[5/15/2019 10:11:52 AM] Loading functions metadata
[5/15/2019 10:11:52 AM] 1 functions loaded
[5/15/2019 10:11:52 AM] WorkerRuntime: dotnet. Will shutdown other standby channels

有人遇到这个问题吗?我应该怎么做才能运行默认的Azure功能模板?

2 个答案:

答案 0 :(得分:0)

最有可能的是,如果您只是尝试运行默认值,则问题出在您的local.settings.json中。

如果打开文件,您将拥有:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

对吗?

如果是这样,则需要将存储连接字符串放在AzureWebJobsStorage中。它看起来像:

DefaultEndpointsProtocol=https;AccountName=<account_name>;AccountKey=<account_key>;EndpointSuffix=core.windows.net

然后该脚本应该运行无误。

答案 1 :(得分:0)

我无法解决您的问题。我正在使用Visual Studio 2017 + Azure开发工具。我也有相同版本的Core Tools v2.0.12438.0。

以下是创建时间触发功能的文档:https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function。在计时器触发器中,您可以指定希望功能应用程序运行的频率。请注意,计划设置是一个六字段的CRON表达式(https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer#cron-expressions),例如,值'0 * / 1 * * * *'将计划您的函数每分钟运行一次。