Worker supports getting job server list from command line options.

This commit is contained in:
David Shrewsbury
2012-09-25 15:30:05 -04:00
parent b00af389d7
commit a4faba5b7f
2 changed files with 23 additions and 9 deletions

View File

@@ -103,7 +103,7 @@ class Options(object):
# generated help from ArgumentParser. # generated help from ArgumentParser.
self.parser.add_argument( self.parser.add_argument(
'-c', '--config', dest='config', default='/etc/libra/libra.ini', '-c', '--config', dest='config', default='/etc/libra/libra.ini',
metavar='FILE', help='Configuration file' metavar='FILE', help='configuration file'
) )
self.parser.add_argument( self.parser.add_argument(
@@ -112,11 +112,11 @@ class Options(object):
) )
self.parser.add_argument( self.parser.add_argument(
'-d', '--debug', dest='debug', action='store_true', '-d', '--debug', dest='debug', action='store_true',
help='Log debugging output' help='log debugging output'
) )
self.parser.add_argument( self.parser.add_argument(
'-v', '--verbose', dest='verbose', action='store_true', '-v', '--verbose', dest='verbose', action='store_true',
help='Log more verbose output' help='log more verbose output'
) )
self.parser.add_argument( self.parser.add_argument(
'-p', '--pid', dest='pid', '-p', '--pid', dest='pid',
@@ -130,7 +130,7 @@ class Options(object):
default='/var/log/libra/libra_{name}.log'.format( default='/var/log/libra/libra_{name}.log'.format(
name=self.shortname name=self.shortname
), ),
help='Log file to use (ignored with --nodaemon)' help='log file to use (ignored with --nodaemon)'
) )
def run(self): def run(self):

View File

@@ -27,7 +27,13 @@ from libra.worker.utils import import_class
def lbaas_task(worker, job): def lbaas_task(worker, job):
""" Main Gearman worker task. """ """
Main Gearman worker task.
This is the function executed by the Gearman worker for incoming requests
from the Gearman job server. It will be executed once per request. Data
comes in as a JSON object, and a JSON object is returned in response.
"""
NODE_OK = "ENABLED" NODE_OK = "ENABLED"
NODE_ERR = "DISABLED" NODE_ERR = "DISABLED"
@@ -146,7 +152,12 @@ def main():
options.parser.add_argument( options.parser.add_argument(
'--driver', dest='driver', '--driver', dest='driver',
choices=known_drivers.keys(), default='haproxy', choices=known_drivers.keys(), default='haproxy',
help='Type of device to use' help='type of device to use'
)
options.parser.add_argument(
'--server', dest='server', action='append', metavar='HOST:PORT',
default=[],
help='add a Gearman job server to the connection list'
) )
args = options.run() args = options.run()
@@ -156,12 +167,15 @@ def main():
# along to the Gearman task that will use it to communicate with # along to the Gearman task that will use it to communicate with
# the device. # the device.
logger.debug("Using driver %s=%s" % (args.driver, logger.debug("Selected driver: %s" % args.driver)
known_drivers[args.driver]))
driver_class = import_class(known_drivers[args.driver]) driver_class = import_class(known_drivers[args.driver])
driver = driver_class() driver = driver_class()
server = Server(['localhost:4730'], args.reconnect_sleep) if not args.server:
args.server.append('localhost:4730')
logger.debug("Job server list: %s" % args.server)
server = Server(args.server, args.reconnect_sleep)
server.logger = logger server.logger = logger
server.driver = driver server.driver = driver