summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2015-04-20 00:06:58 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2015-04-20 05:54:25 +0300
commitebdf440d3b9a0f26d5ce87d498b28a00626db7a7 (patch)
tree6dd259f8beea9857065b757f25c130e810e96b03
parent2274ae31b2daf527477288f71ff2451537dbc435 (diff)
downloadapscheduler-ebdf440d3b9a0f26d5ce87d498b28a00626db7a7.tar.gz
Fixed compatibility with pymongo 3.0
-rw-r--r--apscheduler/jobstores/mongodb.py12
-rw-r--r--tests/test_jobstores.py5
2 files changed, 8 insertions, 9 deletions
diff --git a/apscheduler/jobstores/mongodb.py b/apscheduler/jobstores/mongodb.py
index 8b50c4e..78fa2c7 100644
--- a/apscheduler/jobstores/mongodb.py
+++ b/apscheduler/jobstores/mongodb.py
@@ -42,12 +42,12 @@ class MongoDBJobStore(BaseJobStore):
raise ValueError('The "collection" parameter must not be empty')
if client:
- self.connection = maybe_ref(client)
+ self.client = maybe_ref(client)
else:
connect_args.setdefault('w', 1)
- self.connection = MongoClient(**connect_args)
+ self.client = MongoClient(**connect_args)
- self.collection = self.connection[database][collection]
+ self.collection = self.client[database][collection]
self.collection.ensure_index('next_run_time', sparse=True)
def lookup_job(self, job_id):
@@ -59,7 +59,7 @@ class MongoDBJobStore(BaseJobStore):
return self._get_jobs({'next_run_time': {'$lte': timestamp}})
def get_next_run_time(self):
- document = self.collection.find_one({'next_run_time': {'$ne': None}}, fields=['next_run_time'],
+ document = self.collection.find_one({'next_run_time': {'$ne': None}}, projection=['next_run_time'],
sort=[('next_run_time', ASCENDING)])
return utc_timestamp_to_datetime(document['next_run_time']) if document else None
@@ -96,7 +96,7 @@ class MongoDBJobStore(BaseJobStore):
self.collection.remove()
def shutdown(self):
- self.connection.disconnect()
+ self.client.close()
def _reconstitute_job(self, job_state):
job_state = pickle.loads(job_state)
@@ -123,4 +123,4 @@ class MongoDBJobStore(BaseJobStore):
return jobs
def __repr__(self):
- return '<%s (client=%s)>' % (self.__class__.__name__, self.connection)
+ return '<%s (client=%s)>' % (self.__class__.__name__, self.client)
diff --git a/tests/test_jobstores.py b/tests/test_jobstores.py
index 35879eb..69337a6 100644
--- a/tests/test_jobstores.py
+++ b/tests/test_jobstores.py
@@ -40,8 +40,7 @@ def sqlalchemyjobstore(request):
@pytest.fixture
def mongodbjobstore(request):
def finish():
- connection = store.collection.database.connection
- connection.drop_database(store.collection.database.name)
+ store.client.drop_database(store.collection.database.name)
store.shutdown()
mongodb = pytest.importorskip('apscheduler.jobstores.mongodb')
@@ -289,7 +288,7 @@ def test_mongodb_client_ref():
try:
mongodb.MongoDBJobStore(client='%s:mongodb_client' % __name__)
finally:
- mongodb_client.disconnect()
+ mongodb_client.close()
del mongodb_client