Sunday, 7 July 2019

Pass a decorator's function into Python RQ

How do I pass a decorator's function into a job?

I have a decorator that would run a job using the function.

@job
def queueFunction(passedFunction, *args, **kwargs):
    # Do some stuff
    passedFunction(*args, **kwargs)

def myDecorator(async=True):
    def wrapper(function):
        def wrappedFunc(*args, **kwargs):
            data = DEFAULT_DATA
            if async:
                queueFunction.delay(function, *args, **kwargs)
            else:
                data = queueFunction(function, *args, **kwargs)
            return data
        return wrappedFunc
    return wrapper

I get an error when trying to use it.

Can't pickle <function Model.passedFunction at 0x7f410ad4a048>: it's not the same object as modelInstance.models.Model.passedFunction

Using Python 3.4



from Pass a decorator's function into Python RQ

No comments:

Post a Comment