forked from bloomberg/pybossa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_scheduler.py
34 lines (28 loc) · 1.02 KB
/
run_scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import logging
import os
from redis import StrictRedis
from redis.sentinel import Sentinel
from rq_scheduler.scheduler import Scheduler
from time import sleep
import pybossa.app_settings as app_settings
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
def run_scheduler():
conn_kwargs = {
'db': app_settings.config.get('REDIS_DB') or 0,
'password': app_settings.config.get('REDIS_PWD')
}
if all(app_settings.config.get(attr) for attr in
['REDIS_MASTER_DNS', 'REDIS_PORT']):
master = StrictRedis(host=app_settings.config['REDIS_MASTER_DNS'],
port=app_settings.config['REDIS_PORT'], **conn_kwargs)
else:
sentinel = Sentinel(app_settings.config['REDIS_SENTINEL'])
master = sentinel.master_for(app_settings.config['REDIS_MASTER'], **conn_kwargs)
scheduler = Scheduler(connection=master)
while True:
try:
scheduler.run()
except ValueError:
sleep(600)
if __name__ == '__main__':
run_scheduler()