MCPcopy Create free account
hub / github.com/celery/celery / DatabaseBackend

Class DatabaseBackend

celery/backends/database/__init__.py:52–376  ·  view source on GitHub ↗

The database result backend.

Source from the content-addressed store, hash-verified

50
51
52class DatabaseBackend(BaseBackend):
53 """The database result backend."""
54
55 # ResultSet.iterate should sleep this much between each pool,
56 # to not bombard the database with queries.
57 subpolling_interval = 0.5
58
59 task_cls = Task
60 taskset_cls = TaskSet
61
62 def __init__(self, dburi=None, engine_options=None, url=None, **kwargs):
63 # The `url` argument was added later and is used by
64 # the app to set backend by url (celery.app.backends.by_url)
65 super().__init__(expires_type=maybe_timedelta,
66 url=url, **kwargs)
67 conf = self.app.conf
68
69 # Override retry defaults to preserve backward compatibility.
70 # Previously, DatabaseBackend used a custom @retry decorator that always
71 # retried with max_retries=3. We maintain this behavior by default.
72 # Both settings always have a value, so check if the user set them.
73 # None also means the default.
74 if not conf.value_set_for('result_backend_always_retry') or self.always_retry is None:
75 self.always_retry = True
76 if not conf.value_set_for('result_backend_max_retries') or self.max_retries is None:
77 self.max_retries = 3
78
79 if self.extended_result:
80 self.task_cls = TaskExtended
81
82 self.url = url or dburi or conf.database_url
83
84 # Merge engine options: defaults from config <- constructor overrides
85 # The defaults (pool_pre_ping=True, pool_recycle=3600) are defined in
86 # celery/app/defaults.py under database_engine_options
87 self.engine_options = dict(
88 conf.database_engine_options or {},
89 **(engine_options or {})
90 )
91 self.short_lived_sessions = kwargs.get(
92 'short_lived_sessions',
93 conf.database_short_lived_sessions)
94
95 schemas = conf.database_table_schemas or {}
96 tablenames = conf.database_table_names or {}
97 self.task_cls.configure(
98 schema=schemas.get('task'),
99 name=tablenames.get('task'))
100 self.taskset_cls.configure(
101 schema=schemas.get('group'),
102 name=tablenames.get('group'))
103
104 if not self.url:
105 raise ImproperlyConfigured(
106 'Missing connection string! Do you have the'
107 ' database_url setting set to a real value?')
108
109 engine_callback = kwargs.get(

Calls

no outgoing calls