devatwork / Premotion-Mansion

Developement project for the Premotion Mansion Framework
MIT License
3 stars 0 forks source link

Add a scheduler service to the framework #187

Closed Erikvl87 closed 9 years ago

Erikvl87 commented 10 years ago

Quartz.NET Scheduler:

I have implemented the Quartz.NET Enterprise Scheduler to the framework. http://www.quartz-scheduler.net/

I've added two types to the project.

The Scheduler holds Jobs. On each Job, multiple Tasks can be registered using an xtype descriptor. The descriptor asks for a Task name and the fully qualified class name of the Task.

I've added an abstract Task class that needs to be inherited from. This class implements the Quartz IJob interface. The only thing that is needed to create a Task is to implement the member DoExecute().

For now, I have only implemented a simple scheduler trigger, that takes these three arguments:

These settings can be configured on the xform. The next run will be scheduled depending on the last run.

Because multiple Tasks can be configured per Job, the xform will show the status of each Task separately. It will show if the Task ran successfully, if it gave any exceptions and the Task output (if present).

Example:

I've added an example type called ExampleJob to the TestWebApp project. This Job has multiple Tasks. One of the tasks will always fail (FailingTask), to demonstrate the exception handling. Another one (ExampleTask) will divide random numbers, and could fail or run successfully, depending on the randomly selected divider, that could be zero.

Screenshot:

job

devatwork commented 10 years ago

Wow, impressive @Erikvl87!

Lets sit down next week and discus both the implementation as well as the feature set.

Erikvl87 commented 10 years ago

Thanks @devatwork!

I have some ideas on how to fix the bug that could occur when updating a Job node which I will work out this week.

Lets sit down indeed to discuss the current implementation, and I still need your talk about the Nucleus which I used in this changeset ;)

Erikvl87 commented 10 years ago

I've added a locking mechanism that still allows different Job nodes to be edited at the same time, but prevents that a single Job node is edited by multiple tasks simultaneously. This solves the 2th issue I mentioned in the original pull-request message about the cached Job nodes.

Erikvl87 commented 10 years ago

I have modified the way a Task gets scheduled. It will now take the last run into account when the task is scheduled. I've added a button on the job node to trigger the job immediately, and I have added an endpoint that could be called every X minute(s) to get or keep the scheduler up and running. This endpoint can be found at "/Scheduler/Poke.xts".

This is necessary because the web application could idle timeout after some period, recycle or shutdown (depending on the IIS configuration).

Erikvl87 commented 10 years ago

I've added a simple mail notification option, that sends an email when a task fails. It will be triggered by exceptions and when a task returns false.

Erikvl87 commented 10 years ago

Tasks are now sequentially executed. I will implement tasks that wait for other tasks before they will execute. Tasks that will not have dependencies should then be executed in parallel. I'll try tot make this change somewhere this week.

Erikvl87 commented 10 years ago

Added support for task dependencies (chaining tasks). Tasks without a dependency on another task will start immediately in parallel. When they do have a dependency, they will be started after the depending task has ran successfully.

In the example below (included in the TestWebApp project) tasks 1 and 2 will start immediately in parallel. task 3 will start right after task 1 is finished, and task 4 will start after both task 1 and 3 are completed.

<scheduler:registerTask id="1" label="Example task" type="Premotion.Mansion.Web.TestWebApp.Web.Types.ExampleJob.ExampleTask, Premotion.Mansion.Web.TestWebApp" />
<scheduler:registerTask id="2" label="Failing task" type="Premotion.Mansion.Web.TestWebApp.Web.Types.ExampleJob.FailingTask, Premotion.Mansion.Web.TestWebApp" />
<scheduler:registerTask id="3" waitsFor="1" label="Waiting task" type="Premotion.Mansion.Web.TestWebApp.Web.Types.ExampleJob.WaitingTask, Premotion.Mansion.Web.TestWebApp" />
<scheduler:registerTask id="4" waitsFor="1,3" label="Another Waiting task" type="Premotion.Mansion.Web.TestWebApp.Web.Types.ExampleJob.AnotherWaitingTask, Premotion.Mansion.Web.TestWebApp" />

@devatwork, can we have another meeting to discuss the implementation and feature set? Your opinion is valuable.