【问题标题】:How to create cron expression for hangfire job that executes everyday at some time如何为每天在某个时间执行的hangfire作业创建cron表达式
【发布时间】:2017-03-28 09:34:38
【问题描述】:

我是 cron 表达式的新手。我只需要知道如何为 Hangfire 中的重复作业创建 cron,该作业在每 1 天下午 5 点、凌晨 1 点、下午 2:45 执行一次

了解 Hangfire 也接受标准 CronExpression,我尝试探索此频率的 cron 表达式,但找不到适合它的 -https://en.wikipedia.org/wiki/Cron 我知道如何在 15 分钟内完成? */15 * * * * 我需要每天运行它。

【问题讨论】:

    标签: cron hangfire


    【解决方案1】:

    cronjob schedular 使用的一般语法是:

    # Execute the <b>command</b> every minute of every day.
    * * * * * command
    

    cronjob schedular 使用的所有字段说明:

    # field #   meaning        allowed values
    # -------   ------------   --------------
    #    1      minute         0-59
    #    2      hour           0-23
    #    3      day of month   1-31
    #    4      month          1-12 (or names, see below)
    #    5      day of week    0-7 (0 or 7 is Sun, or use names)
    

    可以使用八个特殊字符串之一来代替前五个字段:

    string         meaning
    ------         -------
    @reboot        Run once, at startup.
    @yearly        Run once a year, "0 0 1 1 *".
    @annually      (same as @yearly)
    @monthly       Run once a month, "0 0 1 * *".
    @weekly        Run once a week, "0 0 * * 0".
    @daily         Run once a day, "0 0 * * *".
    @midnight      (same as @daily)
    @hourly        Run once an hour, "0 * * * *".
    

    在使用间隔 / 后重复工作:

    */15 * * * * command
    
    # This will execute the command after every 15 minutes.
    

    为了在特定时间执行作业,可以使用“,”:

    * 2,20 * * * command
    
    # This will execute the job every minute but at the hours 2 AM and 8 PM.
    

    希望能消除您的疑虑。

    【讨论】:

    • 谢谢。
    • 就像如果我想在一天内工作两次(早上 6 点和下午 6 点),玉米会像 * 6,18 * * *
    • 参考是什么?我需要了解更多详情。
    • 请访问crontab.guru 查看您创建的 cron 作业,这是一个很棒的网站
    • 谢谢你!很棒的网站,我建议去看看,我花了 10 分钟阅读并试图理解其他示例,但这个网站让我有 2 分钟的时间来获得我需要的东西!
    【解决方案2】:

    我正在尝试:

    RecurringJob.AddOrUpdate(() => Console.Write("Recurring"), "*/15 * * * *");
    

    【讨论】:

      猜你喜欢
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 2016-06-05
      • 2020-03-03
      • 1970-01-01
      • 2011-11-11
      相关资源
      最近更新 更多