Просмотр исходного кода

Use a single CELERY_RESULT_DB_TABLENAMES setting (Closes #1415)

Ask Solem 11 лет назад
Родитель
Сommit
f3ee819f4a
3 измененных файлов с 19 добавлено и 17 удалено
  1. 1 2
      celery/app/defaults.py
  2. 3 2
      celery/backends/database/__init__.py
  3. 15 13
      docs/configuration.rst

+ 1 - 2
celery/app/defaults.py

@@ -125,8 +125,7 @@ NAMESPACES = {
         'REDIS_MAX_CONNECTIONS': Option(type='int'),
         'RESULT_BACKEND': Option(type='string'),
         'RESULT_DB_SHORT_LIVED_SESSIONS': Option(False, type='bool'),
-        'RESULT_DB_TASK_TABLENAME': Option('celery_taskmeta'),
-        'RESULT_DB_TASKSET_TABLENAME': Option('celery_tasksetmeta'),
+        'RESULT_DB_TABLENAMES': Option(type='dict'),
         'RESULT_DBURI': Option(),
         'RESULT_ENGINE_OPTIONS': Option(type='dict'),
         'RESULT_EXCHANGE': Option('celeryresults'),

+ 3 - 2
celery/backends/database/__init__.py

@@ -70,8 +70,9 @@ class DatabaseBackend(BaseBackend):
             conf.CELERY_RESULT_DB_SHORT_LIVED_SESSIONS,
         )
 
-        Task.__table__.name = conf.CELERY_RESULT_DB_TASK_TABLENAME
-        TaskSet.__table__.name = conf.CELERY_RESULT_DB_TASKSET_TABLENAME
+        tablenames = conf.CELERY_RESULT_DB_TABLENAMES
+        Task.__table__.name = tablenames.get('task', 'celery_taskmeta')
+        TaskSet.__table__.name = tablenames.get('group', 'celery_tasksetmeta')
 
         if not self.dburi:
             raise ImproperlyConfigured(

+ 15 - 13
docs/configuration.rst

@@ -264,6 +264,12 @@ To use this backend you need to configure it with an
 See `Connection String`_ for more information about connection
 strings.
 
+.. _`Supported Databases`:
+    http://www.sqlalchemy.org/docs/core/engines.html#supported-databases
+
+.. _`Connection String`:
+    http://www.sqlalchemy.org/docs/core/engines.html#database-urls
+
 .. setting:: CELERY_RESULT_ENGINE_OPTIONS
 
 CELERY_RESULT_ENGINE_OPTIONS
@@ -289,23 +295,19 @@ short lived sessions.  This option only affects the database backend.
 Specifying Table Names
 ~~~~~~~~~~~~~~~~~~~~~~
 
-.. setting:: CELERY_RESULT_DB_TASK_TABLENAME
-
-.. setting:: CELERY_RESULT_DB_TASKSET_TABLENAME
+.. setting:: CELERY_RESULT_DB_TABLENAMES
 
 When SQLAlchemy is configured as the result backend, Celery automatically
-creates two tables to store result metadata for tasks.  These settings allow
-you to customize the table names::
-
-    # use custom table names
-    CELERY_RESULT_DB_TASK_TABLENAME = "myapp_taskmeta"
-    CELERY_RESULT_DB_TASKSET_TABLENAME = "myapp_tasksetmeta"
+creates two tables to store result metadata for tasks.  This setting allows
+you to customize the table names:
 
-.. _`Supported Databases`:
-    http://www.sqlalchemy.org/docs/core/engines.html#supported-databases
+.. code-block:: python
 
-.. _`Connection String`:
-    http://www.sqlalchemy.org/docs/core/engines.html#database-urls
+    # use custom table names for the database result backend.
+    CELERY_RESULT_DB_TABLENAMES = {
+        'task': 'myapp_taskmeta',
+        'group': 'myapp_groupmeta',
+    }
 
 Example configuration
 ~~~~~~~~~~~~~~~~~~~~~