gpt4 book ai didi

c# - Azure TimerTrigger 无法在 .NET 7 独立工作进程中工作

转载 作者:行者123 更新时间:2023-12-03 06:27:05 25 4
gpt4 key购买 nike

我正在尝试触发 .NET 7 中的编排函数 TimerTrigger。以下是我创建的函数

    [Function(nameof(FunctionSampleTimer))]
public async Task Run([TimerTrigger("*/5 * * * * *", RunOnStartup = false)] MyInfo myTimer, [DurableClient] DurableTaskClient client, FunctionContext context)
{
var instanceid = Guid.NewGuid().ToString();
var logger = context.GetLogger("TimerFunction");
logger.LogInformation($"Function Ran. Next timer schedule = {myTimer.ScheduleStatus.Next}");
}

上述函数仅在项目创建时第一次每 5 秒触发一次,并且不会再次触发并卡在“主机锁租约已获取...”行上。

控制台输出显示:

[2023-02-20T01:26:52.843Z] Azure Functions .NET Worker (PID: 49120) initialized in debug mode. Waiting for debugger to attach...
[2023-02-20T01:26:53.305Z] The next 5 occurrences of the 'FunctionSampleTimer' schedule (Cron: '0,5,10,15,20,25,30,35,40,45,50,55 * * * * *') will be:
[2023-02-20T01:26:53.307Z] 02/19/2023 17:26:55-08:00 (02/20/2023 01:26:55Z)
[2023-02-20T01:26:53.308Z] 02/19/2023 17:27:00-08:00 (02/20/2023 01:27:00Z)
[2023-02-20T01:26:53.309Z] 02/19/2023 17:27:05-08:00 (02/20/2023 01:27:05Z)
[2023-02-20T01:26:53.310Z] 02/19/2023 17:27:10-08:00 (02/20/2023 01:27:10Z)
[2023-02-20T01:26:53.311Z] 02/19/2023 17:27:15-08:00 (02/20/2023 01:27:15Z)
[2023-02-20T01:26:53.312Z]
[2023-02-20T01:26:53.323Z] Host started (775ms)
[2023-02-20T01:26:53.324Z] Job host started
[2023-02-20T01:26:54.472Z] {
[2023-02-20T01:26:54.473Z] "ProcessId": 49120,
[2023-02-20T01:26:54.474Z] "RuntimeIdentifier": "win10-x64",
[2023-02-20T01:26:54.475Z] "WorkerVersion": "1.8.0.0",
[2023-02-20T01:26:54.476Z] "ProductVersion": "1.8.0-local202209270007\u002B04ccbd8e45bb9017dc30ff5e1343e893a216e173",
[2023-02-20T01:26:54.477Z] "FrameworkDescription": ".NET 7.0.0",
[2023-02-20T01:26:54.478Z] "OSDescription": "Microsoft Windows 10.0.22621",
[2023-02-20T01:26:54.479Z] "OSArchitecture": "X64",
[2023-02-20T01:26:54.480Z] "CommandLine": "C:\\Users\\swkandhi\\source\\repos\\FunctionTimerTrigger\\FunctionTimerTrigger\\bin\\Debug\\net7.0\\FunctionTimerTrigger.dll --host 127.0.0.1 --port 58647 --workerId e70ddb42-819a-45b2-a17c-dca35392699d --requestId 326e359b-9d29-4105-b2f1-9ef01892ae95 --grpcMaxMessageLength 2147483647"
[2023-02-20T01:26:54.481Z] }
[2023-02-20T01:26:54.493Z] Worker process started and initialized.
[2023-02-20T01:26:55.053Z] Executing 'Functions.FunctionSampleTimer' (Reason='Timer fired at 2023-02-19T17:26:55.0194750-08:00', Id=872452e5-4d71-42ea-a16d-d4790ccf38a2)
[2023-02-20T01:26:57.821Z] Host lock lease acquired by instance ID '00000000000000000000000074E57A56'.

最佳答案

我在 .NET 7 独立 Azure 函数中观察了每一分钟和几分钟生成 GUID Id 的情况,它运行成功:

以下是我的测试用例:

<表类=“s-表”><标题>对于每个第一次运行下一次运行 <正文>2分钟是是1分钟是是60秒是是30秒是否5秒是否

每分钟:

enter image description here

每 2 分钟:

enter image description here

每 60 秒:

enter image description here

每 5 秒:

enter image description here

据我所知,CRON 表达式中最短的间隔至少需要 60 秒 - Hostinger - Cron Job Tutorial 的文章中也提到了这一点.

关于c# - Azure TimerTrigger 无法在 .NET 7 独立工作进程中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75503472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com