How to setup recurring scheduled tasks

Posted by Community Admin on 04-Aug-2018 21:48

How to setup recurring scheduled tasks

All Replies

Posted by Community Admin on 27-Oct-2011 00:00

I have read the examples here but I still have questions.

I want to schedule a task to email our users twice a day, at 9am and 4pm. I'm not sure how to go about setting this up. 

So the class itself is responsible for executing the code, and then setting up the next run time, right? What does the code in the global file do? Looks like it's checking to see if there is a task queued up, and if not, it queues one.

If I need to run my task twice a day, should I setup two instances of the task, one for 9am and the other for 4pm? 


Posted by Community Admin on 30-Oct-2011 00:00

Hi, George!
Not being an expert of Sitefinity Scheduled tasks currently, I should say my plans heavilly include them so I'll try to help here (please remember the not being expert part ;).

From what I see, I think that the code in the Global.asax file is added so it can initially schedule the task (ensure the first execution) when the site is started. After it was scheduled, it is up to your ScheduledTask class inheritor to handle the execution and re-schedule itself. So the Bootstrapper is helping Sitefinity to invoke your task for the first time. Once invoked it is up to you to decide whether to reschedule or not and when exactly.

About re-scheduling - I think your task should identify somehow what time is it now when it is invoked and then reschedule itself for the next time, for example if it is 9:00 am, it should schedule for 4 pm if it's 4 pm it should schedule for 9 am on the next day. Simple switch logic that get's complicated a bit by the fact that it is not guaranteed your task execution time will be exactly 9:00 or 16:00, so you will need ot apply some logic to find the nearest schedule time. For example if it is currently 10:00 am you should asume your task is invoked for 9:00 am and schedule the next for 4:00 pm.
You just need to cover those cases and some possible border cases like - task not executed multiple times or the task is executed 12:30 which is exactly between 9 am and 4 pm or 00:30 which is again exactly half of the time that will pass between 4 and 9.

If I were you (given I have a simple problem and know it will not become more complicated such as request for more emails like at 1 pm and 3 pm and so forth) I will go for a stright forward solution and just find the minimum between the task execution date, 9 am and 4 pm, taking seconds and milliseconds into account. This way you minimize the risk of having a task you cannot address. Then you just calculate to which of your schedules the execution time is closer and asume it is invoke for it. Then schedule for the next.

Hope this helps you and also hope it is accurate in terms of factology as I haven't yet gone through the scheduling system of Sitefinity.

Posted by Community Admin on 14-Nov-2011 00:00

Yes, different tasks should be sceduled for different times of the day. But alerts can be generated at time-intervals defined by you, such that you know the tasks that you've got to work on. Looking at your requirement, the Microsoft 2010 Project Management software can be a real benefit. It has a schedule management system which allows user-controlled scheduling too. Before implementing the application, we made sure its features deliver our needs. You  can slo visit their website to know more.

Posted by Community Admin on 20-Jul-2012 00:00

Is there a way to debug a schedule task? I want to do it but VisualStudio is no attaching ever.
Can someone help me with this?

Thanks!

Posted by Community Admin on 20-Jul-2012 00:00

Is there a way to debug a schedule task? I want to do it but VisualStudio is no attaching ever.
Can someone help me with this?

Thanks!

This thread is closed