Better Task Scheduling in Umbraco
Umbraco offers several useful features and one of them is the in-built task scheduling module. The task scheduler allows you to manage tasks that need to be repeated at scheduled intervals at a given time or day of the week from your Umbraco website. Let’s say you want to publish some content on a day when you need to be out of office, and that content needs to be online for a fixed duration of time. With Umbraco, you can schedule the task of publishing and unpublishing content on the certain dates or time without physically having to push the buttons. We can set “publish at” and “un publish” at date & time for each page under ‘Properties’ tab as shown in screen shot below.
Umbraco task scheduler helps you carry out these tasks in a planned way, leaving you worry-free to get on with your day.
A good task scheduler should be able to schedule one-off tasks, create and manage recurring tasks, set the time and date for a future task to occur and allow all this scheduling to happen through an easily understandable user interface.
Well, Umbraco fits the bill on most of these points but it still runs on a basic platform and heavily depends on publicly available URLs to trigger tasks. The Umbraco task scheduling module does have a few other limitations. For example, a non-developer cannot figure out how to schedule a task and view the logs. Also, task scheduling is limited to a recurring task that needs to occur at a fixed interval.
To demonstrate this, let’s look at the following code which when added to the umbracoSettings.config file, allows you to manage a recurring task at a fixed interval:
<scheduledTasks> <!-- add tasks that should be called with an interval (seconds) --> <task log="true" alias="My Scheduled Task" interval="3600" url="https://website.com/umbraco/api/tasks/method" /></scheduledTasks>
This limitation in the Umbraco task scheduler could be a problem for bigger websites or users wanting to run complicated recurring tasks. In those cases, it might be more appropriate to use tools such as Hangfire, Quartz or Windows Task Scheduler. Let’s look at these task scheduling modules one by one:
This open source .NET scheduler can schedule tasks using the built-in LINQ methods or one can build complex schedules with one-line strings by using crontabs. However, since it doesn’t have a UI to view tasks, non-developers find it difficult to understand what’s happening. The Umbraco package called Url Task Scheduler for V7 uses Quartz for scheduling and provides the UI on an Umbraco dashboard. It’s a useful package for developers whereas non-developers need to use caution because there haven’t been any recent updates to the package.
Hangfire is a popular task scheduling solution that has a nicely designed UI which can be accessed from a browser. Users can easily understand when tasks have been called, when they were completed and if any errors occurred during the task. It can be easily integrated with Umbraco and in case of bigger websites with complex tasks, Hangfire offers good value to the users.
- Windows Task Scheduler
The Windows Task Scheduler is very much like the in-built Umbraco scheduler; however, it has 3 major advantages when compared to its counterpart:
- User can set a time and date for a task to be called
- The process of task scheduling is not affected by site and server restarts
- It accommodates for error handling by allowing user to call the task again if an error occurs
While integrating solutions like Hangfire with Umbraco is a good choice for task scheduling in bigger websites, it would be too much of a hassle to get into if the user wants to setup only couple of ordinary tasks.
For example, if the requirement is to run simple scheduled tasks like sending notification emails or alerts daily, or let’s say import data from other sources like the news, inventory etc., then users can achieve this by simply using the Umbraco in-built task scheduler itself.
Hence, we can safely conclude that despite its drawbacks, when it comes to running simple recurring mundane tasks, Umbraco’s in-built task scheduling module offers to be the perfect tool!
Shwetha Bhat | Blogger
Manjunath Govindappa | ASP.NET Technical Lead