Defining Application Config

Below given is the illustrated config file with the comment for each attribute. Each section is explained in greater details below.

<?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>

XecMe Config Section

XecMe uses 2 sections currently viz.
extensions - The section caches dynamic configuration elements that can be used else where in the configuration
taskManager - This is used to define the task in the system. These tasks are defined by the config elements defined in the previous section (extensions)
<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>

extensions Section

The extensions section is for configuring other new configuration element that can be used in the config. In the snippet given below we are defining new configuration elements parallelTaskRunner, timerTaskRunner, eventTaskRunner and scheduledTaskRunner those are used in the taskRunners section explained later. There is also settings section that can be used as appSettings of the config
<extensions>
      <taskRunners>
        <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 Section

This section is for the user to define the tasks in the system/process. As defined in the earlier section there are 4 types of runners that can be used to configure the task.

<taskManager>
    <taskRunners>
      <!-- 
       Different task runners are defining the task appear in the section.
       The order of appearance does not matter
      -->
    </taskRunners>
</taskManager>

Timer Task Runner

  • timerTaskRunner - As the name implies the task runner run the task run every n milliseconds without reentrence. That mean the task is not allowed run while previous occurrence is running. The delay interval starts from the last occurrence completes. Given below are the attributes details
    • name - (Required) Name of the task
    • type - (Required) Fully qualified 5 part .NET type name that implements the ITask interface
    • interval - (Required) This is the time interval for the task
    • recurrence - (Default=-1) This is the maxinmum number of time the timer task be triggered, If you have a positive number the timer task will be trgirred for those number of times and shut itself down. Default values is -1 indicate infinite number of times
    • startDateTime - This is the start date time after which the task will start to trigger. The default value is DateTime.MinValue
    • endDataTime - This is the end date time after which the task will not be triggered. The default value for this is DateTime.MaxValue
    • dayStartTime - (Default = 00:00:00) This is the time of the day after which task will be triggered. If you need a task to trigger every 15 mins between 15:00 thru 18:00, you can configure this for "15:00:00"
    • dayEndTime - (Default = 23:59:59) This is the time of the day after which the task will stop to trigger for that day
    • timeZone - (Default = null which mean local timezone of the server) This is the timezone for which the parameters startDateTime, endDateTime, dayStartTime and dayEndTime converted. It automatically converts the date time to this target timezone before calculating the trigger. Here is the list of the valid timezone

<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>

Event Task Runner

  • eventTaskRunner - Event task runner is reactive task runner, based on event that the task runner subscribed to, the task will be executed.
    • name - (Required) Name of the task
    • type - (Required) Fully qualified 5 part .NET type name that implements the ITask interface
    • eventTopic - This is the name of the event that the task is subscribed to. All the tasks in the system generates ("Task.<Task Name>.Completed") completion event. So if you want to subscribe to any of the configured tasks for completion, you can provide the "Task.<Task Name>.Completed" in the eventTopic
    • threadOption - This defines how the task is executed when the event occurs. There are 3 possible value that threadOption can take viz.
      • PublisherThread - The task is executed on the same thread and the event publisher
      • BackgroundSerial - The task is executed on a single processing thread in the order the events are received
      • BackgroundParallel - The task is executed in parallel threads and does not gaurantee the order of execution vs. order of events
    • timeout - (Default 5000 ms)Timeout is the time that Event Task Runner takes before it shuts down. Since Event are reactive components and there can be some backlog pending to be executed when the task manager is stopped, to ensure all the pending tasks is executed, this is the timeout period the Event Task Runner will wait before shuting down

<eventTaskRunner name="Order Process" 
            taskType="Fully Qualified Task Name of ITask" 
            eventTopic="Name of the event" 
            threadOption="BackgroundParallel|BackgroundSerial|Publisher">
  <!-- 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>

Parallel Task Runner

  • parallelTaskRunner - As the name implies, this runner run the task on multiple threads
    • name - (Required) Name of the task
    • type - (Required) Fully qualified 5 part .NET type name that implements the ITask interface
    • minInstances - This is the minimum number of task that runner will cache for executing the tasks
    • maxInstances - This is the maximum number of parallel instances that runner will run for the task
    • idlePollingPeriod - This is the polling period in millisecond that task will poll to check whether there is work. When there is no work, the last thread will poll periodically until task has some work to execute.
<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>

Scheduled Task Runner

  • scheduledTaskRunner - As name suggested, this runner is schedulable runner.
    • name - (Required) Name of the task
    • type - (Required) Fully qualified 5 part .NET type name that implements the ITask interface
    • repeat - (Default = 1) This value is for the recurring schedule for skipping some occurrences. The default value is 1 indicating the schedule is for every occurrence. If you want to have every other occurrence then set this value to 2
    • recursion - (Required) This is enum value one of the values Daily, Weekly and Monthly
    • startDate - (Default = DateTime.Now) This is the reference date used for calculating the skip where repeat is 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 - This is the time of the day when task gets triggered.
    • schedule - This is an encoded string for recursion
      • Daily - For recursion = Daily, this parameter is ignored
      • Weekly - For recursion = Weekly, this parameter define the week days on which the task can run. 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.
      • Monthly - For recursion = Monthly, this parameter take 2 parts
        • MN : This is the month part taking scheduled month. All is a keyword for all months. It is defined as "MN:January,March"
        • DY: This is the first option of second part which is days of the month and can be defined as "DY:1,2,4,Last,All". Last is the keyword used for last day of the month. All is the keyword for all days of the month. First part and second part is separated by pipe (|). E.g. "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.
        • WK: This is the second option of second part which is configuring by weeks. "WK:First, Second, Last". First, Second, Third and Fourth are the weeks and Last is a keyword for last week irrespective of whether month has 4 or 5 weeks. Along with the weeks we must define which weeks day we want to schedule for the task. Weekday string string looks like "WD:Monday, Tuesday". E.g. 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. Here is the list of the valid Timezone
<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>

Parameters

Task that are implemented can be parametric. For instance, if you want to write a reusable task like FTPing file to a partners site. The parameters for this task are URL, directory, user id, password and file name. These thing can be configured local to the task runner instead of cluttering in the appSettings.
<parameters>
  <parameter name="url" value="sftp.example.com"/>
  <parameter name="userId" value="user"/>
  <parameter name="pwd" value="password"/>
  <parameter name="dir" value="/data/"/>
  <parameter name="file" value="DATA_*.CSV"/>
</parameters>

Last edited Mar 29, 2013 at 12:11 AM by slolam, version 13

Comments

No comments yet.