Przeglądaj źródła

SQLAlchemy: Added setting CELERY_RESULT_ENGINE_OPTIONS to set database engine options.

Example:

    CELERY_RESULT_ENGINE_OPTIONS = {"echo": True}
Ask Solem 15 lat temu
rodzic
commit
cd4ba55ab5
2 zmienionych plików z 10 dodań i 3 usunięć
  1. 5 2
      celery/backends/database.py
  2. 5 1
      celery/conf.py

+ 5 - 2
celery/backends/database.py

@@ -11,12 +11,15 @@ from celery.backends.base import BaseDictBackend
 class DatabaseBackend(BaseDictBackend):
     """The database result backend."""
 
-    def __init__(self, dburi=conf.RESULT_DBURI, **kwargs):
+    def __init__(self, dburi=conf.RESULT_DBURI,
+            engine_options=None, **kwargs):
         self.dburi = dburi
+        self.engine_options = dict(engine_options or {},
+                                   **conf.RESULT_ENGINE_OPTIONS or {})
         super(DatabaseBackend, self).__init__(**kwargs)
 
     def ResultSession(self):
-        return ResultSession(dburi=self.dburi)
+        return ResultSession(dburi=self.dburi, **self.engine_options)
 
     def _store_result(self, task_id, result, status, traceback=None):
         """Store return value and status of an executed task."""

+ 5 - 1
celery/conf.py

@@ -94,7 +94,6 @@ def _get(name, default=None, compat=None):
 ALWAYS_EAGER = _get("CELERY_ALWAYS_EAGER")
 RESULT_BACKEND = _get("CELERY_RESULT_BACKEND", compat=["CELERY_BACKEND"])
 CELERY_BACKEND = RESULT_BACKEND # FIXME Remove in 1.4
-RESULT_DBURI = _get("CELERY_RESULT_DBURI")
 CELERY_CACHE_BACKEND = _get("CELERY_CACHE_BACKEND")
 TASK_SERIALIZER = _get("CELERY_TASK_SERIALIZER")
 TASK_RESULT_EXPIRES = _get("CELERY_TASK_RESULT_EXPIRES")
@@ -105,6 +104,11 @@ ACKS_LATE = _get("CELERY_ACKS_LATE")
 if isinstance(TASK_RESULT_EXPIRES, int):
     TASK_RESULT_EXPIRES = timedelta(seconds=TASK_RESULT_EXPIRES)
 
+# <--- SQLAlchemy                                  <-   --   --- - ----- -- #
+RESULT_DBURI = _get("CELERY_RESULT_DBURI")
+RESULT_ENGINE_OPTIONS = _get("CELERY_RESULT_ENGINE_OPTIONS")
+
+
 # <--- Client                                      <-   --   --- - ----- -- #
 
 MAX_CACHED_RESULTS = _get("CELERY_MAX_CACHED_RESULTS")