如何使用计时器触发器将时区传递给Azure函数 [英] How to pass timezone to Azure function with timer trigger

查看:98
本文介绍了如何使用计时器触发器将时区传递给Azure函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Azure函数,需要在美国东部标准时间上午11点运行.我了解计时器触发器使用UTC,但是出于可读性的目的,是否可以将上午11点传递给run函数?

I created an azure function that I need to run at 11 AM EST time. I understand the timer triggers use UTC however is there a way to pass in 11 AM to the run function for readability purposes?

例如,这是我的run方法,是否可以通过X所在的上午11点并指定时区?

For example here is my run method, is it possible to pass 11 AM where the X sits and specify a timezone?:

public static void Run([TimerTrigger("0 0 X * * *")]TimerInfo myTimer, TraceWriter log)

推荐答案

基于Web应用程序沙箱的Azure函数. Web应用程序需要您首先在环境设置中设置时区. timetrigger属性是函数的声明部分.将在此处检查环境变量.如果未预先设置关于时区的环境变量,则会根据默认的UTC时间对其进行处理.

Azure Function based on Web app sandbox. Web app need you to set the timezone in env settings first. The timetrigger attribute is the declaration part of the function. The environment variables will be checked here. If you do not set the environment variables about the time zone in advance, it will be processed according to the default UTC time.

env变量在本地运行和在azure上运行时来自不同的地方.

The env variable comes from different place when run on local and run on azure.

例如,如果要设置EST时间.

For example, if you want to set EST time.

在本地,您需要在local.settings.json中进行设置.像这样:

On local, you need to set it in local.settings.json. like this:

{
    "IsEncrypted": false,
    "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true",
      "FUNCTIONS_WORKER_RUNTIME": "dotnet",
      "WEBSITE_TIME_ZONE": "US Eastern Standard Time"
    }
}

在Azure上,在此位置设置时区(不要忘记保存更改):

On Azure, set the time zone in this place(dont forget to save the changes):

来自此文档,EST = GMT-5.因此,在您的情况下,如果您处于默认时区,则可以将CRON设置为0 0 6 * * *.由于小时不能为负.因此它对您的情况有效,但不一定适用于其他情况.我建议您使用我一开始建议的方法.

From this doc, EST = GMT - 5. So in your case, if you are in default time zone, you can set the CRON as 0 0 6 * * *. Since the hour cannot be negative. So it is valid for your situation, but not necessarily applicable to other situations. I suggest you use the method I recommended at the beginning.

这篇关于如何使用计时器触发器将时区传递给Azure函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆