summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJose Ignacio Villar <jvillar@gmail.com>2016-07-03 20:21:55 +0200
committerAlex Grönholm <alex.gronholm@nextday.fi>2016-07-03 21:21:55 +0300
commit9eb5dc50c4778ee6771c72a53dd70be3c0040fcf (patch)
tree8958dad581da6f41e1086db8686f6ef246045668 /examples
parent93c4393244ba6989c48f8b5f42b2571ec719cef2 (diff)
downloadapscheduler-9eb5dc50c4778ee6771c72a53dd70be3c0040fcf.tar.gz
Zookeeper jobstore support (#144)
Diffstat (limited to 'examples')
-rw-r--r--examples/jobstores/zookeeper.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/jobstores/zookeeper.py b/examples/jobstores/zookeeper.py
new file mode 100644
index 0000000..12b3e42
--- /dev/null
+++ b/examples/jobstores/zookeeper.py
@@ -0,0 +1,33 @@
+"""
+This example demonstrates the use of the Zookeeper 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('zookeeper', path='/example_jobs')
+ 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