summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2016-07-16 16:25:18 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2016-07-16 16:25:18 +0300
commita6bdea38975667e7f3ca61c97f6877c24da3f00d (patch)
tree9aa98769753f5e9cefa93797b39ed45d52f6e333 /examples
parent3c47d78c98fe4da56d6b0be075c489d7449246fb (diff)
downloadapscheduler-a6bdea38975667e7f3ca61c97f6877c24da3f00d.tar.gz
Updated jobstore related documentation and examples
Added missing API documentation pages for rethinkdb and zookeeper job stores. Also added example script for rethinkdb. Mentioned RethinkDB in README.
Diffstat (limited to 'examples')
-rw-r--r--examples/jobstores/rethinkdb_.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/jobstores/rethinkdb_.py b/examples/jobstores/rethinkdb_.py
new file mode 100644
index 0000000..c1baa0e
--- /dev/null
+++ b/examples/jobstores/rethinkdb_.py
@@ -0,0 +1,33 @@
+"""
+This example demonstrates the use of the RethinkDB 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
+import os
+
+from apscheduler.schedulers.blocking import BlockingScheduler
+
+
+def alarm(time):
+ print('Alarm! This alarm was scheduled at %s.' % time)
+
+
+if __name__ == '__main__':
+ scheduler = BlockingScheduler()
+ scheduler.add_jobstore('rethinkdb', database='apscheduler_example')
+ if len(sys.argv) > 1 and sys.argv[1] == '--clear':
+ scheduler.remove_all_jobs()
+
+ alarm_time = datetime.now() + timedelta(seconds=10)
+ scheduler.add_job(alarm, 'date', run_date=alarm_time, args=[datetime.now()])
+ print('To clear the alarms, run this example with the --clear argument.')
+ print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
+
+ try:
+ scheduler.start()
+ except (KeyboardInterrupt, SystemExit):
+ pass