ITask

ITask, this exposes 4 method for the developers viz.

1. OnStart - This method is called by the framework when this task object is about to be used for the first time. Developer can put the initialization code (like database connection set up, queue initialization etc.) into this method. This method is called only once during the lifetime of the task object.

2. OnExecute - This method should implement the task execution logic. This method will be called everytime when task needs to be performed. This method returns one of the ExecutionState enum value back to the framework. This value helps framework to determine the next course of action for this task. For example, if the method returns value ExecutionState.Recyle then the framework will release the current task object and replace it with a new instance task object. The reason for the recycling can be connection for closed, underlying queue got closed, task object is in inconsistant state and there is a need of reestablishing the connection.

3. OnStop - As the name suggests, this method will be call before the task object is about to released after completion of the task. Developers can place clean up code in this method.

4. OnUnhandledException - This method is called by the framework when there is an exception occured in the task that was not handled by the task. Developer can use this method to log it as critical error. In an ideal scenario this method should never be called.

public class MyTask: ITask
{
    void OnStart(ExecutionContext context)
    {
        ///Implement the initialization here 
    }

    void OnStop(ExecutionContext context)
    {
        ///Implement clean up here 
    }

    ExecutionState OnExecute(ExecutionContext context)
    {
        ///Implement the task processing logic here and make sure you return the appropriate 
        ///ExecutionState value so the framework take the appropriate action
    }

    void OnUnhandledException(Exception exception)
    {
        ///You can implement the exception logging and incident ticket for support.
        ///Although there is this method but control should not come into this method.
    }
}

Last edited Jan 30, 2013 at 9:58 PM by slolam, version 2

Comments

No comments yet.