This project is read-only.

Quick jump start with XecMe

XecMe does 2 distinct functions viz.
  1. Hosting thru XecMeHost.exe for batch job execution or Windows Service. This can be used to host any of your batch jobs and long running unattended process as Window Service
  2. Execution framework, enabling you to write functional Task and wire then together thru events, or let them run in parallel for higher throughput or run task periodically at certain time.

So let start with XecMe
  • Create the functional tasks for your business process by implementing ITask interface. You can implement different such tasks in one or more assemblies
public class MyQueueReader: ITask
{
   ....
    public void OnStart(ExecutionContext context)
    {
         //Setting up a Queue for processing order
    .....
    }

    public ExecutionState OnExecute(ExecutionContext context)  
    {
           //Read the Queue
           //Update the ExecutionContext
    }

    public void OnStop(ExecutionContext context)
    {
         //Clean up the Queue connection
    .....
    }
}

public class MyOrderProcessing: ITask
{
   ....
    public void OnStart(ExecutionContext context)
    {
         //Initialize the task
    .....
    }

    public ExecutionState OnExecute(ExecutionContext context)  
    {
           //Read the ExecutionContext for data
           // Process the order and update

    }

    public void OnStop(ExecutionContext context)
    {
         //Clean up 
    .....
    }
}
  • Once you have all the tasks its time for you to put then together in a process by configuring them together. Divide your tasks into follow execution patterns based on your need.
    • Parallel - for the task which you want to run multiple instances to get higher throughout like reading the queues
    • Event - for the task you want them to run based on certain event like successful execution of other task. Each task in the process upon successfully execution raises an event (event topic name is "Task.<Task Name>.Completed") in the process for other task to consume. You can wire the task together. Eg. I have "Read Queue" Parallel task responsible for reading queues upon each successful completion of reading a event is generated with the event topic name as "Task.Read Queue.Completed". If you configure the eventTopic name to be "Task.Read Queue.Completed" Event task will be executed upon successful execution of Read Queue Parallel task
    • Timer - This will allow the task to run periodically. There is a extensive set of configurations on this type of tasks
      • Recurrence - The task to run for n number of times
      • Between specific dates - Like some tasks you want them to run every hour for first 60 days of the production
      • Between the specific time of the day - Task should run between 3:00 to 6:00 every 15 mins
      • Specific to timezone - You can specify the timezone. This is specifically useful when you deploy on the servers of different timezones
    • Scheduled - This will allow the task to run at scheduled time. You can also schedule recurring time like daily, weekly and monthly. There is extensive set of configurations on this typw of tasks
      • Repeat - This let you skip the recurrence e.g. for daily job, if you want to make it alternate day then set this configuration to 2.
      • Recursion - You can have Daily, Weekly or Monthly based on how often you want to run your task.
      • StartDate - This is very important when you have Repeat parameter greater than 1. If you want the task to run skipping x occurrence, then it becomes important the know the starting point for the occurrence.
      • TaskTime - Time at task gets triggered during the day
      • Schedule - This is an encoded string for recursion e.g. for weekly task we can set the string as "WD:Monday,Friday", this will ensure the task runs only on Mondays and Fridays. For monthy task you can either go with the day of the month or week (first, second, last week etc.) and weekday (Monday, Wednesday etc.). "MN:January, March, December|DY:1,2,Last", this enables the task to run on 1st, 2nd and last day of January, March and December. So to schedule a task on ThanksGiving day the schedule string will look like "MN:November|WD:Thursday|WK:Fourth"
      • TimeZone - This enables the task scheduled time is as per this timezone. If your service is in EST and you want the task to run at 22:00 PST it will automatically converts to the timezone and make sure the task runs at 01:00 EST. It also takes care of the daylight saving change for applicable timezones. More details on Timezone
<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="xecMe.Core" type="XecMe.Configuration.XecMeSectionGroup, XecMe.Configuration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e34de6d98c38471a">
      <section name="extensions" type="XecMe.Configuration.ExtensionsSection, XecMe.Configuration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e34de6d98c38471a"/>
      <section name="taskManager" type="XecMe.Core.Configuration.TaskManagerSection, XecMe.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e34de6d98c38471a"/>
    </sectionGroup>
  </configSections>
  <xecMe.Core>
    <extensions>
      <taskRunners>
        <!-- Whatever is defined in the name below the same tags are to be used in taskRunners section under taskManager -->
        <!-- The type is the type of the element for the defined tag -->
        <!-- One can implement other type of TaskRunner by inheriting from TaskRunner class-->
        <!-- TaskRunnerElement inheriting from TaskRunnerElement class-->
        <add name="parallelTaskRunner" type="XecMe.Core.Configuration.ParallelTaskRunnerElement, XecMe.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e34de6d98c38471a"/>
        <add name="timerTaskRunner" type="XecMe.Core.Configuration.TimerTaskRunnerElement, XecMe.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e34de6d98c38471a"/>
        <add name="eventTaskRunner" type="XecMe.Core.Configuration.EventTaskRunnerElement, XecMe.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e34de6d98c38471a"/>
        <add name="scheduledTaskRunner" type="XecMe.Core.Configuration.ScheduledTaskRunnerElement, XecMe.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e34de6d98c38471a"/>
      </taskRunners>
      <settings>
        <!-- IBatchProcess is needed if you are configuring a batch process-->
        <add name="IBatchProcess" type="Sample.MyBatch, Sample, Version=1.0.0.0, PublicKeyToken=null, Culture=neutral"/>
        <!-- IService is needed if you are configuring a batch process-->
        <add name="IService" type="Sample.MyService, Sample, Version=1.0.0.0, PublicKeyToken=null, Culture=neutral"/>
      </settings>
    </extensions>
    <taskManager>
      <taskRunners>
        <eventTaskRunner name="Order Process" taskType="Fully Qualified Task Name of ITask" eventTopic="Name of the event" threadOption="BackgroundParallel">
          <!-- Parameters serve as input parameters to the task-->
          <parameters>
            <parameter name="test1" value="val1"/>
            <parameter name="test2" value="val2"/>
            <parameter name="test3" value="val3"/>
          </parameters>
        </eventTaskRunner>
        <!-- The taskType attribute should be an impletementation of ITask-->
        <timerTaskRunner name="Queue monitor" 
                         taskType="Fully Qualified Type Name of ITask implementation should go here" 
                         interval="time between the triggers"
                         startDateTime="Start date time for this task"
                         endDateTime="End date time for this task" 
                         dayStartTime="Start time of the day"
                         dayEndTime="End time of the day"
                         recurrence="number of time"
                         timeZone="time zone id string - task will be triggered for this time zone">
          <!-- Parameters serve as input parameters to the task-->
          <parameters>
            <parameter name="test1" value="val1"/>
            <parameter name="test2" value="val2"/>
            <parameter name="test3" value="val3"/>
          </parameters>
        </timerTaskRunner>
        <parallelTaskRunner name="Parallel Task" taskType="Fully qualified type" minInstances="2" maxInstances="10">
          <parameters>
            <parameter name="test1" value="val1"/>
            <parameter name="test2" value="val2"/>
            <parameter name="test3" value="val3"/>
          </parameters>
        </parallelTaskRunner>
        
        <scheduledTaskRunner name="Scheduled Task"
                             taskType="Fully qualified task type"
                             repeat="Skip every x days/weeks/months"
                             recursion="Daily|Weekly|Monthly" 
                             startDate="Date for initial reference"
                             taskTime="Time at which task is triggered"
                             schedule="schedule string for Weekly / Monthly recursion"
                             timeZone="time zone id string - task will be triggered for this time zone">
          <parameters>
            <parameter name="test1" value="val1"/>
            <parameter name="test2" value="val2"/>
            <parameter name="test3" value="val3"/>
          </parameters>
        </scheduledTaskRunner>
      </taskRunners>
    </taskManager>
  </xecMe.Core>
</configuration>
  • Once you have configured your tasks, its time to host them. You can host then using XecMeHost.exe or in your custom host like Worker Role
        TaskManager.Start(new TaskManagerConfig());
        TaskManager.WaitTaskToComplete();
TaskManager will load all the task using reflection and run them based on the configurations. This way you can configure diverse functional tasks in a single process without bothering the context switching, threading model etc.

You can refer the FAQ for question you may have. Feel free to drop a note or comment in case you have issues or difficulties configuring the tasks. I have been using this for all my server side processing needs

Last edited Mar 19, 2013 at 5:35 PM by slolam, version 21

Comments

No comments yet.