Daemonize the worker.

This commit is contained in:
yackob03 2013-10-18 17:52:55 -04:00
parent 2fcd8df42b
commit 607bf3ecc4
4 changed files with 47 additions and 11 deletions

View file

@ -31,3 +31,13 @@ start the workers:
``` ```
python -m workers.diffsworker -D python -m workers.diffsworker -D
``` ```
bouncing the servers:
```
sudo kill -HUP <pid of nginx>
kill -HUP <pid of gunicorn>
kill <pids of worker daemons>
restart daemons
```

View file

@ -14,3 +14,4 @@ mixpanel-py
beautifulsoup4 beautifulsoup4
marisa-trie marisa-trie
apscheduler apscheduler
python-daemon

View file

@ -1,25 +1,29 @@
APScheduler==2.1.1
Flask==0.10.1 Flask==0.10.1
Flask-Login==0.2.7 Flask-Login==0.2.7
Flask-Mail==0.9.0 Flask-Mail==0.9.0
Flask-Principal==0.4.0 Flask-Principal==0.4.0
Jinja2==2.7.1 Jinja2==2.7.1
MarkupSafe==0.18 MarkupSafe==0.18
PyMySQL==0.5 PyMySQL==0.6.1
Werkzeug==0.9.4 Werkzeug==0.9.4
argparse==1.2.1 argparse==1.2.1
beautifulsoup4==4.3.2 beautifulsoup4==4.3.2
blinker==1.3 blinker==1.3
boto==2.13.3 boto==2.15.0
distribute==0.6.34 distribute==0.6.34
eventlet==0.14.0 eventlet==0.14.0
greenlet==0.4.1 greenlet==0.4.1
gunicorn==18.0 gunicorn==18.0
itsdangerous==0.23 itsdangerous==0.23
lockfile==0.9.1
marisa-trie==0.5.1
mixpanel-py==3.0.0 mixpanel-py==3.0.0
peewee==2.1.4 peewee==2.1.4
py-bcrypt==0.4 py-bcrypt==0.4
python-daemon==1.6
python-dateutil==2.1 python-dateutil==2.1
requests==2.0.0 requests==2.0.0
six==1.4.1 six==1.4.1
stripe==1.9.5 stripe==1.9.8
wsgiref==0.1.2 wsgiref==0.1.2

View file

@ -2,6 +2,7 @@ import logging
import json import json
import daemon import daemon
import time import time
import argparse
from apscheduler.scheduler import Scheduler from apscheduler.scheduler import Scheduler
@ -29,7 +30,20 @@ def process_work_items():
else: else:
logger.debug('No work today.') logger.debug('No work today.')
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()
def start_worker(args):
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s' FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s'
if args.D:
logging.basicConfig(filename=args.log, format=FORMAT, level=logging.DEBUG)
else:
logging.basicConfig(format=FORMAT, level=logging.DEBUG) logging.basicConfig(format=FORMAT, level=logging.DEBUG)
sched = Scheduler() sched = Scheduler()
@ -39,3 +53,10 @@ sched.add_interval_job(process_work_items, seconds=10)
while True: while True:
time.sleep(60 * 60 * 24) # sleep one day, basically forever time.sleep(60 * 60 * 24) # sleep one day, basically forever
if args.D:
with daemon.DaemonContext():
start_worker(args)
else:
start_worker(args)