Search code examples
pythoncelerycelery-canvas

Howto use celery.set() method to update properties of abstract base class


I want to use the celery.signature().set() method to change the configuration of my task when calling it in a chain.

Here's what my task looks like

class MyBaseTask(Task)
  myconfig = None


@app.task(base=MyBaseTask)
def mytask():
  print mytask.myconfig

Here's how I would expect to call the chain

chain(mytask.s(message).set(myconfig=config1), mytask.s().set(myconfig=config2))

is this possible? Other task related config can be set like this, queue for instance. How can I expose this behavior in my abstract base class?


Solution

  • No, I don't believe this is possible because celery currently keeps a white-list of values that can be transmitted as part of the message sent to the broker. Normally you would just pass the dynamic content as an input parameter to your task if you want to change it dynamically.

    def mytask(myconfig):
        print mytask.myconfig