Continuous WebJob with timer trigger

后端 未结 1 1143
走了就别回头了
走了就别回头了 2020-12-16 16:38

I have written following functions in continuous web job :

public static void fun1([TimerTrigger(\"24:00:00\", RunOnStartup = true, UseMonitor = true)] Timer         


        
相关标签:
1条回答
  • 2020-12-16 17:11

    You should have a look at the documentation of the TimerTriggerAttribute:

    • The first parameter you specified is the schedule expression: This can either be a 6 field crontab expression or a System.TimeSpan.

    A Cron expression can be represented like that:

    *    *    *    *    *    *  command to be executed
    ┬    ┬    ┬    ┬    ┬    ┬
    │    │    │    │    │    │
    │    │    │    │    │    │
    │    │    │    │    │    └───── day of week (0 - 7) (0 or 7 are Sunday, or    use names)
    │    │    │    │    └────────── month (1 - 12)
    │    │    │    └─────────────── day of month (1 - 31)
    │    |    └──────────────────── hour (0 - 23)
    │    └───────────────────────── min (0 - 59)
    └────────────────────────────── second(0 - 59)
    

    In you case, the expression is a string represening a TimeSpan :

    • "24:00:00" : this job is running every 24 hours, RunOnStartup : this means the job will run when the webjob starts or restarts even if the last run occured in the last 24 hours.

    • "00:01:00" : this job is running every minute, RunOnStartup : this means the job will run when the webjob starts or restarts even if the last run occured in the last minute.

    EDIT

    From this answer:

    • TimerTrigger - TimeSpan "24:00:00" - The next 5 occurrences as being 24 days apart

    This is due to the way TimeSpan.Parse works. If you pass it "24:00:00" strangely enough it will give you back a TimeSpan of duration 24 days. Not sure if this is their intended behavior or a bug on their side, but we simply pass the expression down to them and inherit their behavior. Anyhow, for your purposes, to get 24 hours you can use "1.00:00" (specifying 1 day).

    0 讨论(0)
提交回复
热议问题