Daemonize the worker.
This commit is contained in:
parent
2fcd8df42b
commit
607bf3ecc4
4 changed files with 47 additions and 11 deletions
10
README.md
10
README.md
|
@ -31,3 +31,13 @@ start the workers:
|
|||
```
|
||||
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
|
||||
```
|
||||
|
|
|
@ -13,4 +13,5 @@ eventlet
|
|||
mixpanel-py
|
||||
beautifulsoup4
|
||||
marisa-trie
|
||||
apscheduler
|
||||
apscheduler
|
||||
python-daemon
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
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)
|
||||
|
|
Reference in a new issue