summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2014-02-01 17:52:47 +0200
committerAlex Grönholm <alex.gronholm@nextday.fi>2014-03-09 10:13:55 +0200
commitedbc940a9d9206b0a81d4067484e8a8cadaa035b (patch)
tree50dcfca1d6b5157cf39cff8b9230f1b93385cd2e /examples
parent17aae6293ce5f090477d48e15d25cf5b34a906ad (diff)
downloadapscheduler-edbc940a9d9206b0a81d4067484e8a8cadaa035b.tar.gz
Overhauled the job store system and ditched ShelveJobStore and RedisJobStore in the process
Diffstat (limited to 'examples')
-rw-r--r--examples/jobstores/mongodb.py (renamed from examples/persistent.py)12
-rw-r--r--examples/jobstores/sqlalchemy_.py31
-rw-r--r--examples/misc/reference.py (renamed from examples/reference.py)0
3 files changed, 38 insertions, 5 deletions
diff --git a/examples/persistent.py b/examples/jobstores/mongodb.py
index 1e1a155..49f1f0b 100644
--- a/examples/persistent.py
+++ b/examples/jobstores/mongodb.py
@@ -1,13 +1,15 @@
"""
-This example demonstrates the use of persistent job stores.
+This example demonstrates the use of the MongoDB job store.
On each run, it adds a new alarm that fires after ten seconds.
You can exit the program, restart it and observe that any previous alarms that have not fired yet are still active.
+Running the example with the --clear switch will remove any existing alarms.
"""
from datetime import datetime, timedelta
+import sys
from apscheduler.schedulers.blocking import BlockingScheduler
-from apscheduler.jobstores.shelve import ShelveJobStore
+from apscheduler.jobstores.mongodb import MongoDBJobStore
def alarm(time):
@@ -16,10 +18,10 @@ def alarm(time):
if __name__ == '__main__':
scheduler = BlockingScheduler()
- scheduler.add_jobstore(ShelveJobStore('example.db'), 'shelve')
+ scheduler.add_jobstore(MongoDBJobStore(collection='example_jobs'))
alarm_time = datetime.now() + timedelta(seconds=10)
- scheduler.add_job(alarm, 'simple', [alarm_time], jobstore='shelve', args=[datetime.now()])
- print('To clear the alarms, delete the example.db file.')
+ scheduler.add_job(alarm, 'date', [alarm_time], args=[datetime.now()])
+ print('To clear the alarms, run this example with the --clear argument.')
print('Press Ctrl+C to exit')
try:
diff --git a/examples/jobstores/sqlalchemy_.py b/examples/jobstores/sqlalchemy_.py
new file mode 100644
index 0000000..561c3f8
--- /dev/null
+++ b/examples/jobstores/sqlalchemy_.py
@@ -0,0 +1,31 @@
+"""
+This example demonstrates the use of the SQLAlchemy job store.
+On each run, it adds a new alarm that fires after ten seconds.
+You can exit the program, restart it and observe that any previous alarms that have not fired yet are still active.
+You can also give it the database URL as an argument. See the SQLAlchemy documentation on how to construct those.
+"""
+
+from datetime import datetime, timedelta
+import sys
+
+from apscheduler.schedulers.blocking import BlockingScheduler
+from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
+
+
+def alarm(time):
+ print('Alarm! This alarm was scheduled at %s.' % time)
+
+
+if __name__ == '__main__':
+ scheduler = BlockingScheduler()
+ url = sys.argv[1] or 'sqlite://example.sqlite'
+ scheduler.add_jobstore(SQLAlchemyJobStore(url))
+ alarm_time = datetime.now() + timedelta(seconds=10)
+ scheduler.add_job(alarm, 'date', [alarm_time], args=[datetime.now()])
+ print('To clear the alarms, delete the example.sqlite file.')
+ print('Press Ctrl+C to exit')
+
+ try:
+ scheduler.start()
+ except (KeyboardInterrupt, SystemExit):
+ pass
diff --git a/examples/reference.py b/examples/misc/reference.py
index 2b0c414..2b0c414 100644
--- a/examples/reference.py
+++ b/examples/misc/reference.py