Skip to content

Commit

Permalink
MongoDB: Pickle url with backend. Closes celery#2347
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Nov 18, 2014
1 parent 83d51e8 commit 9e0eae6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions celery/backends/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MongoBackend(BaseBackend):

_connection = None

def __init__(self, **kwargs):
def __init__(self, app=None, url=None, **kwargs):
"""Initialize MongoDB backend instance.
:raises celery.exceptions.ImproperlyConfigured: if
Expand All @@ -68,7 +68,7 @@ def __init__(self, **kwargs):
"""
self.options = {}

super(MongoBackend, self).__init__(**kwargs)
super(MongoBackend, self).__init__(app, **kwargs)

if not pymongo:
raise ImproperlyConfigured(
Expand Down Expand Up @@ -100,10 +100,10 @@ def __init__(self, **kwargs):
self.options.setdefault('max_pool_size', self.max_pool_size)
self.options.setdefault('auto_start_request', False)

url = kwargs.get('url')
if url:
self.url = url
if self.url:
# Specifying backend as an URL
self.host = url
self.host = self.url

def _get_connection(self):
"""Connect to the MongoDB server."""
Expand Down Expand Up @@ -232,9 +232,9 @@ def cleanup(self):
)

def __reduce__(self, args=(), kwargs={}):
kwargs.update(
dict(expires=self.expires))
return super(MongoBackend, self).__reduce__(args, kwargs)
return super(MongoBackend, self).__reduce__(
args, dict(kwargs, expires=self.expires, url=self.url),
)

def _get_database(self):
conn = self._get_connection()
Expand Down

0 comments on commit 9e0eae6

Please sign in to comment.