本文整理汇总了Python中pyres.worker.Worker类的典型用法代码示例。如果您正苦于以下问题:Python Worker类的具体用法?Python Worker怎么用?Python Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Worker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pyres_worker
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)
示例2: pyres_worker
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: test_working_on
def test_working_on(self):
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
self.resq.enqueue(Basic,"test1")
job = Job.reserve('basic', self.resq)
worker = Worker(['basic'])
worker.working_on(job)
assert self.redis.exists("resque:worker:%s" % name)
示例4: test_unregister
def test_unregister(self):
worker = Worker(['basic'])
worker.register_worker()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert self.redis.sismember('resque:workers',name)
worker.unregister_worker()
assert name not in self.redis.smembers('resque:workers')
示例5: spawn_worker
def spawn_worker(self, queues):
pid = os.fork()
if not pid:
Worker.run(queues, interval=1)
os._exit(0)
else:
return pid
示例6: handle_noargs
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: pyres_worker
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)
示例8: pyres_worker
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)
示例9: test_job_failure
def test_job_failure(self):
self.resq.enqueue(ErrorObject)
worker = Worker(['basic'])
worker.process()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert not self.redis.get('resque:worker:%s' % worker)
assert self.redis.get("resque:stat:failed") == str(1)
assert self.redis.get("resque:stat:failed:%s" % name) == str(1)
示例10: working
def working(request):
workers = Worker.working(resq._server)
template = env.get_template('working.html')
dic = {
'all_workers':Worker.all(HOST),
'workers':workers,
'resq': resq
}
return str(template.render(dic))
示例11: test_started
def test_started(self):
worker = Worker(['basic'])
dt = datetime.datetime.utcnow()
worker.started = dt
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert self.redis.get('resque:worker:%s:started' % name) == str(int(calendar.timegm(dt.utctimetuple())))
assert worker.started == str(int(calendar.timegm(dt.utctimetuple())))
worker.started = None
assert not self.redis.exists('resque:worker:%s:started' % name)
示例12: test_started
def test_started(self):
import datetime
worker = Worker(['basic'])
dt = datetime.datetime.now()
worker.started = dt
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert self.redis.get('resque:worker:%s:started' % name).decode() == str(int(time.mktime(dt.timetuple())))
assert worker.started.decode() == str(int(time.mktime(dt.timetuple())))
worker.started = None
assert not self.redis.exists('resque:worker:%s:started' % name)
示例13: test_startup
def test_startup(self):
worker = Worker(['basic'])
worker.startup()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert self.redis.sismember('resque:workers',name)
import signal
assert signal.getsignal(signal.SIGTERM) == worker.shutdown_all
assert signal.getsignal(signal.SIGINT) == worker.shutdown_all
assert signal.getsignal(signal.SIGQUIT) == worker.schedule_shutdown
assert signal.getsignal(signal.SIGUSR1) == worker.kill_child
示例14: test_started
def test_started(self):
import datetime
worker = Worker(['basic'])
dt = datetime.datetime.now()
worker.started = dt
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert self.redis.get('resque:worker:%s:started' % name) == dt.strftime('%Y-%m-%d %H:%M:%S')
assert worker.started == datetime.datetime.strptime(dt.strftime('%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
worker.started = None
assert not self.redis.exists('resque:worker:%s:started' % name)
示例15: test_enqueue_from_string
def test_enqueue_from_string(self):
self.resq.enqueue_from_string('tests.Basic','basic','test1')
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert self.redis.llen("resque:queue:basic") == 1
job = Job.reserve('basic', self.resq)
worker = Worker(['basic'])
worker.process(job)
assert not self.redis.get('resque:worker:%s' % worker)
assert not self.redis.get("resque:stat:failed")
assert not self.redis.get("resque:stat:failed:%s" % name)