Description of the Sueetie Background Task architecture enabling multi-threading processes to support system and custom functions.
Sueetie Background Tasks - Patterns
Sueetie includes a background tasks architecture that enables multiple processes to run simultaneously, thus improving the performance and scalability of your Online Community Application. Background tasks are possible through IIS multi-threading, where each background task runs on its own processing thread.
Background Tasks Configuration File
Background Tasks are defined in /tasks.config. Here is a sample tasks.config file.
<?xml version="1.0"?>
<Tasks>
<Task name="WriteSqlRecordTask"
type="Sueetie.Core.Tasks.WriteSqlRecordTask, Sueetie.Core"
minutes="5"
enabled="false"
hour="10"
/>
<Task name="SleepAwhileTask"
type="Sueetie.Core.Tasks.SleepAwhileTask, Sueetie.Core"
minutes="10.2"
enabled="true"
/>
</Tasks>
Each task contains its own
XML Element with required properties:
name, type, minutes and
enabled. The
node is sent to the task as an Xml.Linq.XElement type so any additional properties can be added, as in "hour" shown above.
Launching Background Tasks
Sueetie Background Tasks are launched in the Global.asax Application_Start() event. The following code reads the contents of the /tasks.config file and sends it to the Sueetie Task Scheduler which loads the tasks into their own thread.
XDocument doc = XDocument.Load(Server.MapPath("~/tasks.config"));
this._scheduler = new SueetieTaskScheduler(doc);
this._scheduler.StartTasks();
Background Task Essential Classes
The architecture of Sueetie Background Tasks is very straightforward, consisting of three classes in Sueetie.Core:
iSueetieTask, SueetieTask and
SueetieTaskScheduler. The actual tasks live in the Sueetie.Core.Tasks folder.

Background Task Reporting
A Background Tasks Report is available in Sueetie Administration showing you what background tasks are running, their run interval and successful execution.

Creating Custom Background Tasks
Creating custom background tasks in Sueetie is very easy as you can see from a complete Tasks class below. The class inherits from iSueetieTask and requires an Execute(XElement) method.

Add the task to the /tasks.config file and touch your web.config to restart the application which will reload the background tasks.
Sueetie Background Tasks - Origins
The Sueetie Background Tasks Architecture was based on Keyvan Nayyeri's
Adibar ASP.NET Task Scheduling Framework. Abidar is licensed under the MIT License and
is available on CodePlex.Sueetie Background Task logic was also influenced by the Tasks architecture of Jaben Cargman's YetAnotherForum.NET version 1.9.4, currently in beta. That source is
available at SourceForge and licensed under the GNU General Public License.
The essential modifications found in the Sueetie implementation of Background Tasks from Keyvan's Abidar framework are:
- Passing XDocument to Task Scheduler rather than XmlNodeList and using Xml.Linq for processing the XDocument elements.
- Loading all tasks from /tasks.config for reporting purposes rather than only those marked "Enabled." Only tasks flagged as Enabled will execute on the designated time span interval.
- Changed interval to Minutes, as I felt it was easier to think in terms of minutes rather than interval where 60000 intervals = 1 minute.
- Removed the Priority property, deciding to run all background tasks at same priority level.
- Passing XElement type to Task rather than XmlNode
The YetAnotherNET 1.9.4 release includes a Tasks Reporting function as you can see below. Using a similar approach as YAF 1.9.4 task reporting I added the ability to create an instance of the all SueetieTask objects loaded and a Generic List of those instances for the Sueetie Control Panel Background Tasks Display.
Top