本文整理汇总了Python中pyres.worker.Worker.work方法的典型用法代码示例。如果您正苦于以下问题:Python Worker.work方法的具体用法?Python Worker.work怎么用?Python Worker.work使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyres.worker.Worker
的用法示例。
在下文中一共展示了Worker.work方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import work [as 别名]
def handle(self, queue_list, **options):
queues = queue_list.split(',')
log_level = getattr(logging, options['log_level'].upper(), 'INFO')
setup_logging(procname="pyres_worker", log_level=log_level, filename=None)
setup_pidfile(settings.PYRES_WORKER_PIDFILE)
interval = settings.PYRES_WORKER_INTERVAL
worker = Worker(
queues=queues,
server=settings.PYRES_HOST,
password=settings.PYRES_PASSWORD,
timeout=settings.PYRES_WORKER_TIMEOUT
)
if interval is not None:
worker.work(interval)
else:
worker.work()
示例2: test_kills_stale_workers_after_timeout
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import work [as 别名]
def test_kills_stale_workers_after_timeout(self):
import signal
timeout = 1
worker = Worker(['basic'], timeout=timeout)
self.resq.enqueue(TimeoutJob, timeout + 1)
child = os.fork()
if child:
assert worker.get_failed() == 0
time.sleep(timeout + 2)
os.kill(child, signal.SIGKILL)
os.waitpid(-1, os.WNOHANG)
assert worker.get_failed() == 1
else:
worker.work()
示例3: pyres_worker
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import work [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("--password", dest="password", default="")
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.')
parser.add_option("-t", '--timeout', dest='timeout', default=None, help='the timeout in seconds for this worker')
(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 = '%s:%s' % (options.host,options.port)
#Worker.run(queues, server, interval, password=options.password, timeout=timeout)
worker = Worker(queues=queues, server=server, password=options.password, timeout=timeout)
if (interval is not None):
worker.work(interval)
else:
worker.work()
示例4: int
# 需要导入模块: from pyres.worker import Worker [as 别名]
# 或者: from pyres.worker.Worker import work [as 别名]
from os import environ
from pyres.worker import Worker
from pyres import ResQ
import redis
from tasks import *
redisHost = environ.get("REDIS_QUEUE_HOST")
redisPort = int(environ.get("REDIS_QUEUE_PORT"))
redisPassword = environ.get("REDIS_QUEUE_PASSWORD")
redisObject = redis.Redis(host=redisHost, port=redisPort, password=redisPassword)
r = ResQ(redisObject)
w = Worker(queues=['*'], server=r)
w.work()