Move common code out.

main
Wichert Akkerman 13 years ago
parent 9f7d608da8
commit ec0e4776b4

@ -0,0 +1,16 @@
import redis
from rq import use_connection
def add_standard_arguments(parser):
parser.add_argument('--host', '-H', default='localhost',
help='The Redis hostname (default: localhost)')
parser.add_argument('--port', '-p', type=int, default=6379,
help='The Redis portnumber (default: 6379)')
parser.add_argument('--db', '-d', type=int, default=0,
help='The Redis database (default: 0)')
def setup_redis(args):
redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db)
use_connection(redis_conn)

@ -4,10 +4,11 @@ import sys
import os import os
import time import time
import argparse import argparse
import redis
from redis.exceptions import ConnectionError from redis.exceptions import ConnectionError
from rq import use_connection, Queue, Worker from rq import Queue, Worker
from rq.utils import gettermsize, make_colorizer from rq.utils import gettermsize, make_colorizer
from rq.scripts import add_standard_arguments
from rq.scripts import setup_redis
red = make_colorizer('darkred') red = make_colorizer('darkred')
green = make_colorizer('darkgreen') green = make_colorizer('darkgreen')
@ -133,9 +134,7 @@ def show_both(args):
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description='RQ command-line monitor.') parser = argparse.ArgumentParser(description='RQ command-line monitor.')
parser.add_argument('--host', '-H', default='localhost', help='The Redis hostname (default: localhost)') add_standard_arguments(parser)
parser.add_argument('--port', '-p', type=int, default=6379, help='The Redis portnumber (default: 6379)')
parser.add_argument('--db', '-d', type=int, default=0, help='The Redis database (default: 0)')
parser.add_argument('--path', '-P', default='.', help='Specify the import path.') parser.add_argument('--path', '-P', default='.', help='Specify the import path.')
parser.add_argument('--interval', '-i', metavar='N', type=float, default=2.5, help='Updates stats every N seconds (default: don\'t poll)') parser.add_argument('--interval', '-i', metavar='N', type=float, default=2.5, help='Updates stats every N seconds (default: don\'t poll)')
parser.add_argument('--raw', '-r', action='store_true', default=False, help='Print only the raw numbers, no bar charts') parser.add_argument('--raw', '-r', action='store_true', default=False, help='Print only the raw numbers, no bar charts')
@ -163,9 +162,7 @@ def main():
if args.path: if args.path:
sys.path = args.path.split(':') + sys.path sys.path = args.path.split(':') + sys.path
# Setup connection to Redis setup_redis(args)
redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db)
use_connection(redis_conn)
try: try:
if args.only_queues: if args.only_queues:
func = show_queues func = show_queues

@ -2,10 +2,11 @@
import sys import sys
import argparse import argparse
import logbook import logbook
import redis
from logbook import handlers from logbook import handlers
from rq import use_connection, Queue, Worker from rq import Queue, Worker
from redis.exceptions import ConnectionError from redis.exceptions import ConnectionError
from rq.scripts import add_standard_arguments
from rq.scripts import setup_redis
def format_colors(record, handler): def format_colors(record, handler):
@ -40,9 +41,7 @@ def setup_loghandlers(args):
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description='Starts an RQ worker.') parser = argparse.ArgumentParser(description='Starts an RQ worker.')
parser.add_argument('--host', '-H', default='localhost', help='The Redis hostname (default: localhost)') add_standard_arguments(parser)
parser.add_argument('--port', '-p', type=int, default=6379, help='The Redis portnumber (default: 6379)')
parser.add_argument('--db', '-d', type=int, default=0, help='The Redis database (default: 0)')
parser.add_argument('--burst', '-b', action='store_true', default=False, help='Run in burst mode (quit after all work is done)') parser.add_argument('--burst', '-b', action='store_true', default=False, help='Run in burst mode (quit after all work is done)')
parser.add_argument('--name', '-n', default=None, help='Specify a different name') parser.add_argument('--name', '-n', default=None, help='Specify a different name')
@ -60,10 +59,7 @@ def main():
sys.path = args.path.split(':') + sys.path sys.path = args.path.split(':') + sys.path
setup_loghandlers(args) setup_loghandlers(args)
setup_redis(args)
# Setup connection to Redis
redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db)
use_connection(redis_conn)
try: try:
queues = map(Queue, args.queues) queues = map(Queue, args.queues)
w = Worker(queues, name=args.name) w = Worker(queues, name=args.name)

Loading…
Cancel
Save