Windows service with tree-based job definitions

I’m currently working on  new, fresh, greenfield project. The basic structure is a server which keeps track of a lot of clients and distributes actions for them to perform, and a client service which listens for these actions and enqueue themfor processing.

As I was thinking on how to translate this into code, I realized that flexibility will be key here. I decided on creating a class called “ActionRunner” which is basically a class which accepts IActionSpec implementations and has a RunNext method for processing the queue.

The IActionSpec interface is simple:

IEnumerable<IActionSpec> Act();

We only want to run the action, and then enqueue any action which results from that one. This gives us the possibility of dynamically changing the logic based on outside parameters, and helps us write clean, testable code. It makes sense really. An action is only responsible for deciding which actions to be run based on it’s state, not when to run them. This makes the actions easily testable, since we can create an action with parameters, and then do a check on the returning actions without having to mock out more than the bare minimums.

Next time we’ll have a look at some of the code. (As long as i can get the formatter plugin to work correctly..)

-lars

Tags: , ,