• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python worker.Worker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyres.worker.Worker的典型用法代码示例。如果您正苦于以下问题:Python Worker类的具体用法?Python Worker怎么用?Python Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Worker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:houndci,项目名称:python,代码行数:33,代码来源:worker.py


示例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)
开发者ID:Pyres,项目名称:pyres,代码行数:27,代码来源:scripts.py


示例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)
开发者ID:duxiaoyao,项目名称:pyres,代码行数:7,代码来源:test_worker.py


示例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')
开发者ID:duxiaoyao,项目名称:pyres,代码行数:7,代码来源:test_worker.py


示例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
开发者ID:PAStheLoD,项目名称:pyres,代码行数:7,代码来源:test_worker.py


示例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)
开发者ID:geros,项目名称:pyres_django,代码行数:27,代码来源:pyres_worker.py


示例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)
开发者ID:LatinQueen4Life,项目名称:pyres,代码行数:25,代码来源:scripts.py


示例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)
开发者ID:SMFOSS,项目名称:pyres,代码行数:32,代码来源:scripts.py


示例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)
开发者ID:duxiaoyao,项目名称:pyres,代码行数:8,代码来源:test_worker.py


示例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))
开发者ID:deepu,项目名称:pyres,代码行数:9,代码来源:server.py


示例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)
开发者ID:duxiaoyao,项目名称:pyres,代码行数:9,代码来源:test_worker.py


示例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)
开发者ID:Affectiva,项目名称:pyres,代码行数:10,代码来源:test_worker.py


示例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
开发者ID:duxiaoyao,项目名称:pyres,代码行数:10,代码来源:test_worker.py


示例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)
开发者ID:aezell,项目名称:pyres,代码行数:10,代码来源:test_worker.py


示例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)
开发者ID:fakechris,项目名称:pyres,代码行数:10,代码来源:test_resq.py


示例16: 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)
开发者ID:aezell,项目名称:pyres,代码行数:10,代码来源:test_resq.py


示例17: test_state

 def test_state(self):
     worker = Worker(['basic'])
     assert worker.state() == 'idle'
     self.resq.enqueue_from_string('tests.Basic','basic','test1')
     worker.register_worker()
     job = Job.reserve('basic', self.resq)
     worker.working_on(job)
     assert worker.state() == 'working'
     worker.done_working()
     assert worker.state() == 'idle'
开发者ID:duxiaoyao,项目名称:pyres,代码行数:10,代码来源:test_worker.py


示例18: test_info

 def test_info(self):
     self.resq.enqueue(Basic, "test1")
     self.resq.enqueue(TestProcess)
     info = self.resq.info()
     assert info["queues"] == 2
     assert info["servers"] == ["localhost:6379"]
     assert info["workers"] == 0
     worker = Worker(["basic"])
     worker.register_worker()
     info = self.resq.info()
     assert info["workers"] == 1
开发者ID:aezell,项目名称:pyres,代码行数:11,代码来源:test_resq.py


示例19: test_processed

 def test_processed(self):
     name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
     worker = Worker(['basic'])
     worker.processed()
     assert self.redis.exists("stat:processed")
     assert self.redis.exists("stat:processed:%s" % name)
     assert self.redis.get("stat:processed") == 1
     assert self.redis.get("stat:processed:%s" % name) == 1
     worker.processed()
     assert self.redis.get("stat:processed") == 2
     assert self.redis.get("stat:processed:%s" % name) == 2
开发者ID:deepu,项目名称:pyres,代码行数:11,代码来源:tests.py


示例20: test_failed

 def test_failed(self):
     name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
     worker = Worker(['basic'])
     worker.failed()
     assert self.redis.exists("resque:stat:failed")
     assert self.redis.exists("resque:stat:failed:%s" % name)
     assert self.redis.get("resque:stat:failed") == 1
     assert self.redis.get("resque:stat:failed:%s" % name) == 1
     worker.failed()
     assert self.redis.get("resque:stat:failed") == 2
     assert self.redis.get("resque:stat:failed:%s" % name) == 2
开发者ID:fakechris,项目名称:pyres,代码行数:11,代码来源:test_worker.py



注:本文中的pyres.worker.Worker类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python kd_tree.resample_gauss函数代码示例发布时间:2022-05-27
下一篇:
Python job.Job类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap