本文整理汇总了Python中pyres.worker.Worker.run方法的典型用法代码示例。如果您正苦于以下问题:Python Worker.run方法的具体用法?Python Worker.run怎么用?Python Worker.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyres.worker.Worker
的用法示例。
在下文中一共展示了Worker.run方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pyres_worker
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def pyres_worker():
usage = "usage: %prog [options] arg1"
parser = OptionParser(usage=usage)
parser.add_option("--host", dest="host", default="localhost")
parser.add_option("--port", dest="port", type="int", default=6379)
parser.add_option(
"-i", "--interval", dest="interval", default=None, help="the default time interval to sleep between runs"
)
parser.add_option(
"-l",
"--log-level",
dest="log_level",
default="info",
help='log level. Valid values are "debug", "info", "warning", "error", "critical", in decreasing order of verbosity. Defaults to "info" if parameter not specified.',
)
parser.add_option("-f", dest="logfile", help="If present, a logfile will be used.")
(options, args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
parser.error("Argument must be a comma seperated list of queues")
log_level = getattr(logging, options.log_level.upper(), "INFO")
setup_logging(log_level=log_level, filename=options.logfile)
interval = options.interval
if interval is not None:
interval = float(interval)
queues = args[0].split(",")
server = "%s:%s" % (options.host, options.port)
Worker.run(queues, server, interval)
示例2: pyres_worker
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def pyres_worker():
usage = "usage: %prog [options] arg1"
parser = OptionParser(usage=usage)
parser.add_option("--host", dest="host", default="localhost")
parser.add_option("--port",dest="port",type="int", default=6379)
parser.add_option("-i", '--interval', dest='interval', default=None, help='the default time interval to sleep between runs')
parser.add_option('-l', '--log-level', dest='log_level', default='info', help='log level. Valid values are "debug", "info", "warning", "error", "critical", in decreasing order of verbosity. Defaults to "info" if parameter not specified.')
parser.add_option('-f', dest='logfile', help='If present, a logfile will be used. "stderr", "stdout", and "syslog" are all special values.')
parser.add_option('-p', dest='pidfile', help='If present, a pidfile will be used.')
(options,args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
parser.error("Argument must be a comma seperated list of queues")
log_level = getattr(logging, options.log_level.upper(), 'INFO')
setup_logging(procname="pyres_worker", log_level=log_level, filename=options.logfile)
setup_pidfile(options.pidfile)
interval = options.interval
if interval is not None:
interval = int(interval)
queues = args[0].split(',')
server = '%s:%s' % (options.host,options.port)
Worker.run(queues, server, interval)
示例3: pyres_worker
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def pyres_worker():
usage = "usage: %prog [options] arg1"
parser = OptionParser(usage=usage)
parser.add_option("--host", dest="host", default="localhost")
parser.add_option("--port",dest="port",type="int", default=6379)
parser.add_option("-i", '--interval', dest='interval', default=None, help='the default time interval to sleep between runs')
parser.add_option('-l', '--log-level', dest='log_level', default='info', help='log level. Valid values are "debug", "info", "warning", "error", "critical", in decreasing order of verbosity. Defaults to "info" if parameter not specified.')
parser.add_option('-f', dest='logfile', help='If present, a logfile will be used.')
parser.add_option("-n", "--nonblocking-pop", dest="blocking_pop", action="store_false", default=True, help="If absent, Pyres will use the Redis blocking pop (BLPOP) to obtain jobs from the queue(s). If present, Redis will use a non-blocking pop (LPOP) and will sleep for up to 8 seconds if no jobs are available.")
(options,args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
parser.error("Argument must be a comma seperated list of queues")
log_level = getattr(logging, options.log_level.upper(), 'INFO')
setup_logging(log_level=log_level, filename=options.logfile)
interval = options.interval
if interval is not None:
interval = int(interval)
queues = args[0].split(',')
server = '%s:%s' % (options.host,options.port)
Worker.run(queues, server, options.blocking_pop, interval)
示例4: spawn_worker
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def spawn_worker(self, queues):
pid = os.fork()
if not pid:
Worker.run(queues, interval=1)
os._exit(0)
else:
return pid
示例5: pyres_worker
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def pyres_worker():
"""Worker CLI, lightly modified from pyres.
"""
usage = 'usage: %prog [options] arg1'
parser = OptionParser(usage=usage)
parser.add_option('--host', dest='host', default=settings['host'])
parser.add_option('--port', dest='port', type='int', default=settings['port'])
parser.add_option('--password', dest='password', default=settings['password'])
parser.add_option('-i', '--interval', dest='interval', default=None)
parser.add_option('-l', '--log-level', dest='log_level', default='info')
parser.add_option('-f', dest='logfile')
parser.add_option('-p', dest='pidfile')
parser.add_option('-t', '--timeout', dest='timeout')
options, args = parser.parse_args()
if len(args) != 1:
parser.print_help()
parser.error("Argument must be a comma seperated list of queues")
log_level = getattr(logging, options.log_level.upper(), 'INFO')
setup_logging(procname="pyres_worker", log_level=log_level, filename=options.logfile)
setup_pidfile(options.pidfile)
interval = options.interval
if interval is not None:
interval = int(interval)
timeout = options.timeout and int(options.timeout)
queues = args[0].split(',')
server = '{0}:{1}'.format(options.host, options.port)
Worker.run(queues, server, options.password, interval, timeout=timeout)
示例6: handle_noargs
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def handle_noargs(self, **options):
queues = (environ.get('QUEUES') or environ.get('QUEUE') or
getattr(settings, 'PYRES_QUEUES', None))
if not queues:
raise CommandError('A list of queues should be specified for '
'worker to run. Try set PYRES_QUEUES django settings '
'variable or QUEUES environment variable, e.g.\n'
'$ QUEUES=q1,q2 python2 management.py pyres_worker')
if isinstance(queues, basestring):
queues = queues.split(',')
server = "%s:%d" % (getattr(settings, 'REDIS_HOST',
'localhost'), getattr(settings, 'REDIS_PORT', 6379))
try:
interval = int(options.get('interval'))
except ValueError:
raise CommandError('Interval must be an integer')
log_level = getattr(logging, options.get('log_level').upper(),
'INFO')
setup_logging("pyres", log_level=log_level,
filename=options.get('log_file'))
Worker.run(queues, server, interval)
示例7: run
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
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)
示例8: main
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def main(argv=sys.argv):
"""
Launches a pyres worker using the host and queues provided
by the config keys `pyres.host` and `pyres.queues`
"""
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
settings = get_appsettings(config_uri)
host = settings['pyres.host']
queues = settings['pyres.queues'].strip().split(',')
setup_logging(procname="notaliens.tasks.worker", log_level="INFO")
Worker.run(queues, server=host)
示例9: main
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def main(args=None):
if args is None:
args = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument('--conf', '-c', help="Path to configuration file.")
parser.add_argument('--verbose', '-v', action='count', default=0, help='Log level: v=warning, vv=info, vvv=debug.')
options = parser.parse_args(args)
log_level = LOGS[options.verbose].upper()
logging.basicConfig(
level=getattr(logging, log_level),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
if options.conf:
cfg = Config.load(abspath(expanduser(options.conf)))
else:
cfg = Config()
conn = ResQ(server="%s:%s" % (cfg.REDIS_HOST, cfg.REDIS_PORT), password=cfg.REDIS_PASSWORD)
conn.config = cfg
connect(
cfg.MONGO_DB,
host=cfg.MONGO_HOST,
port=cfg.MONGO_PORT,
username=cfg.MONGO_USER,
password=cfg.MONGO_PASS
)
print
print("--- Wight worker started ---")
print
Worker.run([WorkerJob.queue], conn)
print
print "--- Wight worker killed ---"
print
示例10: main
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def main():
Worker.run([queue_name], server=config.get('nephelae', 'resque_server'))
示例11: setup_logging
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
# -*- coding: utf-8 -*-
from pyres import setup_logging
from pyres.worker import Worker
from eventq import eventQ
from callq import callQ
setup_logging(procname="barista", log_level="INFO", filename="/tmp/barista.log")
Worker.run(["baristaEvent", "baristaCall"])
示例12: pyres_worker
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import run [as 别名]
def pyres_worker(queue, log_filename=None):
"""Start the pyres worker on the queue"""
#setup_logging(log_level=logging.INFO, filename=log_filename)
Worker.run([queue], server='%s:%d' % (config.REDIS_HOST, config.REDIS_PORT))