diff --git a/README.md b/README.md index 7391cf8e8..b852a4a2d 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,13 @@ start the workers: ``` python -m workers.diffsworker -D ``` + +bouncing the servers: + +``` +sudo kill -HUP +kill -HUP + +kill +restart daemons +``` diff --git a/requirements-nover.txt b/requirements-nover.txt index f35cc670b..fe43012cd 100644 --- a/requirements-nover.txt +++ b/requirements-nover.txt @@ -13,4 +13,5 @@ eventlet mixpanel-py beautifulsoup4 marisa-trie -apscheduler \ No newline at end of file +apscheduler +python-daemon \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e637b3718..171930241 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,25 +1,29 @@ +APScheduler==2.1.1 Flask==0.10.1 Flask-Login==0.2.7 Flask-Mail==0.9.0 Flask-Principal==0.4.0 Jinja2==2.7.1 MarkupSafe==0.18 -PyMySQL==0.5 +PyMySQL==0.6.1 Werkzeug==0.9.4 argparse==1.2.1 beautifulsoup4==4.3.2 blinker==1.3 -boto==2.13.3 +boto==2.15.0 distribute==0.6.34 eventlet==0.14.0 greenlet==0.4.1 gunicorn==18.0 itsdangerous==0.23 +lockfile==0.9.1 +marisa-trie==0.5.1 mixpanel-py==3.0.0 peewee==2.1.4 py-bcrypt==0.4 +python-daemon==1.6 python-dateutil==2.1 requests==2.0.0 six==1.4.1 -stripe==1.9.5 +stripe==1.9.8 wsgiref==0.1.2 diff --git a/workers/diffsworker.py b/workers/diffsworker.py index 84d595d30..519460c5f 100644 --- a/workers/diffsworker.py +++ b/workers/diffsworker.py @@ -2,6 +2,7 @@ import logging import json import daemon import time +import argparse from apscheduler.scheduler import Scheduler @@ -29,13 +30,33 @@ def process_work_items(): else: logger.debug('No work today.') -FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s' -logging.basicConfig(format=FORMAT, level=logging.DEBUG) -sched = Scheduler() -sched.start() +parser = argparse.ArgumentParser(description='Worker daemon to compute diffs') +parser.add_argument('-D', action='store_true', default=False, + help='Run the worker in daemon mode.') +parser.add_argument('--log', default='diffsworker.log', + help='Specify the log file for the worker as a daemon.') +args = parser.parse_args() -sched.add_interval_job(process_work_items, seconds=10) +def start_worker(args): + FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s' -while True: - time.sleep(60 * 60 * 24) # sleep one day, basically forever \ No newline at end of file + if args.D: + logging.basicConfig(filename=args.log, format=FORMAT, level=logging.DEBUG) + else: + logging.basicConfig(format=FORMAT, level=logging.DEBUG) + + sched = Scheduler() + sched.start() + + sched.add_interval_job(process_work_items, seconds=10) + + while True: + time.sleep(60 * 60 * 24) # sleep one day, basically forever + +if args.D: + with daemon.DaemonContext(): + start_worker(args) + +else: + start_worker(args)