Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In my application I have a set of jobs to execute:

  • Each job goes through the states "not started", "started", "completed", "failed" etc.
  • Each job has a set of pre-conditions and post-conditions.
  • Job cannot start until the preconditions are satisfied and should be marked as failed if it doesn't satisfy the post conditions.

For example let's say the job imports a text file into the database. Pre-condition would be to check if the source file exists and post-condition would be to check if data exists in database. On top of these pre and post-conditions, sometimes job is also dependent on other jobs to finish. It is easy to create a jobs table and have a dependency table for jobs, but is it actually possible to make these pre and post validation checks to be configurable in database (so that no code changes need to be made if these conditions change or new conditions are added)?

Even if it is possible somehow, is it a good idea to do so? There is a requirement to make this model generic so that other applications can also make use of it even if the validation checks to be performed are entirely different for other applications.

share|improve this question
    
Rule 31 in The Pragmatic Programmer. Design by Contract would help. –  Ubermensch Jan 13 '12 at 15:57
    
State –  gnat Jan 13 '12 at 16:52
add comment

2 Answers 2

up vote 1 down vote accepted

but is it actually possible to make these pre and post validation checks to be configurable in database (so that no code changes need to be made if these conditions change or new conditions are added)?

Yes. It's trivially possible. There are lots of techniques.

  1. Invent your own domain-specific language for this. And write your own interpreter.

  2. Use BPEL.

  3. Use any dynamic language (Python, Ruby, Lua, etc.) and put code in the database.

is it a good idea to do so?

No.

Code is best represented as code.

The pre-condition checks are often best left as code. Ant, Maven and Scons all provide ways of doing this in code.

There is a requirement to make this model generic so that other applications can also make use of it even if the validation checks to be performed are entirely different for other applications.

Read up on Ant, Maven and Scons for approaches that work nicely.

Also, there are many commercial products that do this.

Finally, you should be able to Google "open source batch schedulers" and find even more solutions to this well-understood and already-solved problem.

You don't really need to solve this again.

share|improve this answer
add comment

You could theoretically make a precondition and post condition table that linked to jobs, but the implementation would be extremely complex. I would first determine the frequency of changes to job dependencies and based on that make a decision whether its worth it to create such a system. If you find changes are likely to happen weekly that is a completely different scenario than yearly.

Also a requirement to make something generic is one that is easy to say, but much harder to implement and can be unrealistic for a lot of applications. are there currently applications that exist that are intended to be able to use this job manager? are the applications intended to use this generic solution similar enough that a generic solution can actually solve the needs of all applications? It is worth it if you have doubts to examine if a generic solution is actually what is needed or if its is even possible, then tell your manager that I know that this project required a generic solution, but that will take X months longer than than this solution, or we can't create a generic solution that would be acceptable because the target applications are too different.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.