• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Hangfire Cron表达式无效

用户头像
it1352
帮助3

问题说明

我正在使用Hangfire,我想为我的RecurringJobs描述不同的情况。但是我无法实现我想要的目标,如果CRON已经受到限制,那么Hangfire使用的CRON还会更多。

I am using Hangfire and I want to describe different scenarios for my RecurringJobs. But I am not being able to achieve what I am looking for, and if CRON is already limited, the CRON used by Hangfire is yet more.

我继续阅读Hangfire文档,发现有一个 https://en.wikipedia.org/wiki/Cron#CRON_expression 用于获得比Hangfire默认支持的表达式更复杂的表达式。但是它们甚至不兼容,例如,Hangfire仅具有分钟,小时,月,日,星期几,但是如果我使用L或?在文档上说的那一天是行不通的。我遇到此错误以下表达式 16 14 L的错误? ?

I went on reading Hangfire documentation and I find a like to https://en.wikipedia.org/wiki/Cron#CRON_expression for more complex expressions then the ones supported by default on Hangfire. But they are not even compatible, for instance, Hangfire only has minutes, hour, month, day, days of the week, but if I use the L or the ? on the day like it says on the documentation it does not work. I have this error the following error for this expression 16 14 L ? ?:

InnerException = {"'L' is not a valid [Day] crontab field value. It must be a numeric value between 1 and 31 (all inclusive)."}

Changfire的CRON具有以下方法: Monthly(int day); 如果我选择实例31会发生什么?仍然会在每个月的最后一天(例如2月或4月)运行?还是我需要做一些额外的事情来实现它?

CRON from Hangfire has the following method: Monthly(int day); What happens If I choose for instance 31? It will still run on months like February or April for instance at the last day of each month? Or do I need to do something extra to achieve it?

那样发生了什么?我似乎无法定义用户选择的一天的条件是31,以便始终在每月的最后一天运行后台作业。而且,我什至不谈论第29或30天,这也是特殊原因,我将始终使用该月的最后一天来处理后台作业。

That way what is happening? I do not seem able to define the condition of the day chosen by the user is 31, to run the background jobs always on the last day of the month. And I don't even talk about days 29 or 30 which are also special causes and which I would use always the last day of the month to process the background job.

我虽然使用了Hangfire.CRON的Month方法,但我认为它不会像我想要的那样对待29,30和31天。

I though of using the Month method from Hangfire.CRON but I don't think it will treat the days 29,30 and 31 the way I want.

您是否确认Hangfire Cron不使用文档所引用的Cron表达式,是否有任何方法可以实现我所寻找的?另外,有没有建议的教程或其他可以帮助我的东西?我一直在阅读 https://github.com/atifaziz/NCrontab ,我认为这是一个Hangfire可以使用,但并不能帮上大忙。

Do you confirm that Hangfire Cron does not use the Cron expressions that are referenced by documentation and if there is any way to achieve what I am looking for? Also, any suggested tutorial or something to help me out? I have been reading https://github.com/atifaziz/NCrontab which I think it is the one Hangfire uses, but it does not help that much.

正确答案

#1

您对 NCrontab 。 Hangfire使用它,因此您应确保此库支持cron表达式。有两个简单的方法可以做到这一点:

You are right about NCrontab. Hangfire uses it, so you should ensure your cron expression is supported by this library. Two simple options to do it:

    • C#交互式窗口(如NCrontab自述文件所述,也可以使用示例)
  • C# Interactive window (as described in NCrontab Readme, or you could use this example )
  • Online cron visualizer (like https://crontab.guru or http://cron.schlitt.info)

Cron.Monthly(31)转换为 0 0 31 * * ,并且仅当当前月份为 31 天时才会触发作业。

Cron.Monthly(31) is translated to 0 0 31 * * and job would be triggered only if current month has 31 days.

要始终在该月的最后一天运行后台作业,请添加三个单独的作业:

To run the background job always on the last day of the month, add three separate jobs:

0 0 30 4,6,9,11        *
0 0 31 1,3,5,7,8,10,12 *
0 0 28 2               *

计划在该月的最后一天运行的作业

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhbikicf
系列文章
更多 icon
同类精品
更多 icon
继续加载