NAMD / pypelinin

Python library to distribute jobs and pipelines among a cluster
3 stars 5 forks source link

Broker should filter which objects it imports #17

Open turicas opened 11 years ago

turicas commented 11 years ago

Should not be needed to specify a __all__ in the workers module: Broker should inspect the module for classes that inherit from pypelinin.Worker.

turicas commented 11 years ago

Maybe (but probably not) we can use decorators instead of inheritance to specify that a class is a worker, but probably a better approach is to use inheritance since we can add helper methods to Worker.

israelst commented 11 years ago

We could use both solutions. Use inheritance and the decorator which we have done together.

def Worker(requires):
    def Worker2(worker_function):
        class WorkerClass(object):
            def process(self, document):
                document['passou'] = 'por aqui'
                return worker_function(document)
        WorkerClass.requires = requires
        return WorkerClass
    return Worker2

@Worker(requires=['teste'])
def Teste(document):
    return document