【发布时间】:2013-11-20 11:30:02
【问题描述】:
我目前正在开发一个基于 django-tenants-schema 的 Django 应用程序。您不需要查看模块的实际代码,但想法是它具有当前数据库连接的全局设置,定义用于应用程序租户的架构,例如
tenant = tenants_schema.get_tenant()
对于设置
tenants_schema.set_tenant(xxx)
对于 一些 任务,我希望他们记住在实例化期间选择的当前全局租户,例如理论上:
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'])
在芹菜中有没有优雅的做法?
【问题讨论】: