Support forum for ASP.NET Zero (https://aspnetzero.com/).
User avatar
By ajayak
#31506 Hi,

I have created a background worker that should run on 1st of every month. I can easily do this using hangfire cron jobs but I'm not sure, what is the effect of Timer.Period property has on this.

If I skip entering the timer property, I get exception.
If I fill Timer property, I don't want the code to execute on any other day than 1st of every month.

What is the best approach to achieve this? :D

I'm using something like below:
Code: Select allRecurringJob.AddOrUpdate<InvoiceBackgroundWorker>(job => job.Start(), Cron.MonthInterval(0));
By BobIngham
#31528 @ajayak,
Hope this helps.
This definition will run at midnight, first day of the month.
Code: Select allRecurringJob.AddOrUpdate<InvoiceBackgroundWorker>(job => job.Start(), "0 0 1 * *");

I'm sure it will be fired by server time and not by system time and therefore Timer.Period should be irrelevant.
That's why clocks go back and forward at 02:00 and not 01:00!!!!
If you have a system which has several timezones then it's another matter altogether, you will need a job to run at the offset between server time and UTC to run each hour and process data for each timezone in the system. Good luck with that if that's what you have to do. I once worked on a global betting system which had to do something similar!
User avatar
By ajayak
#31540
BobIngham wrote:@ajayak,
Hope this helps.
This definition will run at midnight, first day of the month.
Code: Select allRecurringJob.AddOrUpdate<InvoiceBackgroundWorker>(job => job.Start(), "0 0 1 * *");

I'm sure it will be fired by server time and not by system time and therefore Timer.Period should be irrelevant.
That's why clocks go back and forward at 02:00 and not 01:00!!!!
If you have a system which has several timezones then it's another matter altogether, you will need a job to run at the offset between server time and UTC to run each hour and process data for each timezone in the system. Good luck with that if that's what you have to do. I once worked on a global betting system which had to do something similar!


Thanks @BobIngham,

But how will Timer property affect this? Does that mean the job will run with cron and with the set timer?
By BobIngham
#31541 Hi @ajayak, I think I see the problem but I can't comment without seeing your code. You shouldn't need the timer at all, I think you're mixing implementations of Zero's background workers and Hangfire when you really only need one or the other. Can you show me the code where you are referring to Timer.Period and I will try advise accordingly.
By ryancyq
#31548 Hi @ajayak, it seems to me that Timer.Period is to configure how frequent does your job timer runs. However the Cron format should be use for actual job scheduled timings.

For example, timer runs at 30 mins interval and Cron job specific 12:00am. The worst case scenario will be timer trigger at 11:59pm then Cron job will not execute. The next interval for Cron job to execute will be at 12.29am
Last edited by ryancyq on Sat Aug 18, 2018 11:22 am, edited 1 time in total.