diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2020-10-06 21:34:06 +0300 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2020-10-06 21:34:06 +0300 |
commit | 15477e6d7005b31ae6caf4e141f9f31717382bd0 (patch) | |
tree | 5d01ec97992f40775a247e550aa30f7e81601959 | |
parent | 43f564d3851ad9b0f45ad76d74caefb623154128 (diff) | |
download | apscheduler-15477e6d7005b31ae6caf4e141f9f31717382bd0.tar.gz |
Upgraded mongodb job store to PyMongo 3.0
-rw-r--r-- | apscheduler/jobstores/mongodb.py | 12 | ||||
-rw-r--r-- | docs/versionhistory.rst | 2 | ||||
-rw-r--r-- | setup.py | 2 |
3 files changed, 9 insertions, 7 deletions
diff --git a/apscheduler/jobstores/mongodb.py b/apscheduler/jobstores/mongodb.py index 7dbc3b1..ea3097d 100644 --- a/apscheduler/jobstores/mongodb.py +++ b/apscheduler/jobstores/mongodb.py @@ -54,7 +54,7 @@ class MongoDBJobStore(BaseJobStore): def start(self, scheduler, alias): super(MongoDBJobStore, self).start(scheduler, alias) - self.collection.ensure_index('next_run_time', sparse=True) + self.collection.create_index('next_run_time', sparse=True) @property def connection(self): @@ -83,7 +83,7 @@ class MongoDBJobStore(BaseJobStore): def add_job(self, job): try: - self.collection.insert({ + self.collection.insert_one({ '_id': job.id, 'next_run_time': datetime_to_utc_timestamp(job.next_run_time), 'job_state': Binary(pickle.dumps(job.__getstate__(), self.pickle_protocol)) @@ -96,13 +96,13 @@ class MongoDBJobStore(BaseJobStore): 'next_run_time': datetime_to_utc_timestamp(job.next_run_time), 'job_state': Binary(pickle.dumps(job.__getstate__(), self.pickle_protocol)) } - result = self.collection.update({'_id': job.id}, {'$set': changes}) - if result and result['n'] == 0: + result = self.collection.update_one({'_id': job.id}, {'$set': changes}) + if result and result.matched_count == 0: raise JobLookupError(job.id) def remove_job(self, job_id): - result = self.collection.remove(job_id) - if result and result['n'] == 0: + result = self.collection.delete_one({'_id': job_id}) + if result and result.deleted_count == 0: raise JobLookupError(job_id) def remove_all_jobs(self): diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 6476ef1..623b3e2 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -10,6 +10,8 @@ APScheduler, see the :doc:`migration section <migration>`. * Fixed Zookeeper job store using backslashes instead of forward slashes for paths on Windows (PR by Laurel-rao) * Pinned ``tzlocal`` to a version compatible with pytz +* Fixed deprecation warnings on the MongoDB job store and increased the minimum PyMongo + version to 3.0 3.6.3 @@ -47,7 +47,7 @@ setup( ':python_version == "2.7"': ['futures', 'funcsigs'], 'asyncio:python_version == "2.7"': ['trollius'], 'gevent': ['gevent'], - 'mongodb': ['pymongo >= 2.8'], + 'mongodb': ['pymongo >= 3.0'], 'redis': ['redis >= 3.0'], 'rethinkdb': ['rethinkdb >= 2.4.0'], 'sqlalchemy': ['sqlalchemy >= 0.8'], |