summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2014-04-13 22:13:31 -0400
committerAlex Grönholm <alex.gronholm@nextday.fi>2014-04-13 22:13:31 -0400
commitf123c7d8fabef4c3d13961b3d4b3a7a37a74cfaf (patch)
treed5b5ef6a9452c13af4c13f454c991da0fb151260 /examples
parent5d5ca2ef24ae5c70444f92975eacb98465822d55 (diff)
downloadapscheduler-f123c7d8fabef4c3d13961b3d4b3a7a37a74cfaf.tar.gz
Added missing redis example
Diffstat (limited to 'examples')
-rw-r--r--examples/jobstores/redis_.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/jobstores/redis_.py b/examples/jobstores/redis_.py
new file mode 100644
index 0000000..8236e5c
--- /dev/null
+++ b/examples/jobstores/redis_.py
@@ -0,0 +1,34 @@
+"""
+This example demonstrates the use of the Redis 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.redis import RedisJobStore
+
+
+def alarm(time):
+ print('Alarm! This alarm was scheduled at %s.' % time)
+
+
+if __name__ == '__main__':
+ scheduler = BlockingScheduler()
+ jobstore = RedisJobStore(jobs_key='example.jobs', run_times_key='example.run_times')
+ if len(sys.argv) > 1 and sys.argv[1] == '--clear':
+ jobstore.remove_all_jobs()
+
+ scheduler.add_jobstore(jobstore)
+ 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+C to exit')
+
+ try:
+ scheduler.start()
+ except (KeyboardInterrupt, SystemExit):
+ pass