Skip to content

Commit

Permalink
Upgraded mongodb job store to PyMongo 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Oct 6, 2020
1 parent 43f564d commit 15477e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions apscheduler/jobstores/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, database='apscheduler', collection='jobs', client=None,

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):
Expand Down Expand Up @@ -83,7 +83,7 @@ def get_all_jobs(self):

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))
Expand All @@ -96,13 +96,13 @@ def update_job(self, job):
'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):
Expand Down
2 changes: 2 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
':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'],
Expand Down

0 comments on commit 15477e6

Please sign in to comment.