title: Django celery task keep global state
body: <p>I am currently developing a Django application based on django-tenants-schema. You don't need to look into the actual code of the module, but the idea is that it has a global setting for the current database connection defining which schema to use for the application tenant, e.g. </p>
  
  <pre><code>tenant = tenants_schema.get_tenant()
  </code></pre>
  
  <p>And for setting</p>
  
  <pre><code>tenants_schema.set_tenant(xxx)
  </code></pre>
  
  <p>For <em>some</em> of the tasks I would like them to remember the current global tenant selected during the instantiation, e.g. in theory:</p>
  
  <pre><code>class AbstractTask(Task):
      '''
      Run this method before returning the task future
      '''
      def before_submit(self):
           self.run_args['tenant'] = tenants_schema.get_tenant()
  
      '''
      This method is run before related .run() task method
      '''
      def before_run(self):
           tenants_schema.set_tenant(self.run_args['tenant'])
  </code></pre>
  
  <p>Is there an elegant way of doing it in celery?</p>