forked from dsjoerg/ggpyjobs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
executable file
·68 lines (54 loc) · 1.92 KB
/
worker.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
#
# This is using daemon.py from https://github.com/serverdensity/python-daemon
from pyres.worker import Worker
import logging
from pyres import setup_logging, setup_pidfile
import yaml
from daemon import Daemon
import os, sys, inspect, time, socket, errno
from datetime import datetime
import simplejson
# Deprecated, maintaining 2.6 compat here though
# http://docs.python.org/library/optparse.html
from optparse import OptionParser
class gg(Daemon):
def run(self):
import ggtracker
from ggtracker.utils import django_setup
from django.conf import settings
django_setup()
if options.logfile != '':
setup_logging(procname="pyres_worker", log_level='INFO', filename=options.logfile)
else:
setup_logging(procname="pyres_worker", log_level='INFO')
# setup_pidfile(options.pidfile)
Worker.run(['python', 'python-low', 'python-bg'], settings.REDIS_SERVER)
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-p", "--path", dest="path", help="application root path", metavar="APP_ROOT", default=".")
parser.add_option("-e", "--env", dest="env", help="application environment", metavar="RACK_ENV", default="development")
parser.add_option("-i", "--pidfile", dest="pidfile", help="pid file", default="/tmp/gg.pid")
parser.add_option("-l", "--logfile", dest="logfile", help="log file", default="")
(options, args) = parser.parse_args()
if options.env:
os.environ['RACK_ENV'] = options.env
if options.path:
os.environ['APP_ROOT'] = options.path
daemon = gg(options.pidfile)
if len(args) >= 1:
if 'start' == args[0]:
daemon.start()
elif 'stop' == args[0]:
daemon.stop()
elif 'restart' == args[0]:
daemon.restart()
elif 'run' == args[0]:
daemon.run()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)