Adding behaviour for managing "task" dependencies

David wizzardx at gmail.com
Fri Oct 5 04:25:05 EDT 2007


>
> Any thoughts would be most appreciated, though I would like to stress
> that I don't think Python should support the syntax I'm proposing I'd
> just like to know if I can extend a copy of it to do that.
>

You can use syntax like this:

class MyJob1(Job):
    depends(MyJob2)
    depends(MyJob3)

Or with quotes (if MyJob2 and MyJob3 could be declared later):

class MyJob1(Job):
    depends('MyJob2')
    depends('MyJob3')

(where 'depends' is a DSL-like construct. See Elixir
(elixir.ematia.de) for an example of how to implement DSL statements
like "depends". Check their implementation of the "belongs_to"
statement.

You could also extend your "depends" dsl statement to allow more than
one dep at a time, eg:

class MyJob1(Job):
    depends('MyJob2', 'MyJob3')

Whatever approach you use, you should also look into implementing
"topological sort" logic. This lets you resolve programatically which
order the inter-dependent tasks should be handled in to satisfy their
dependencies.

You may find this module interesting in this regard:

http://pypi.python.org/pypi/topsort

David.



More information about the Python-list mailing list