当前位置: 首页>>代码示例>>Python>>正文


Python rq.Worker方法代码示例

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


在下文中一共展示了rq.Worker方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_transport_shutdown

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def test_transport_shutdown(sentry_init, capture_events_forksafe):
    sentry_init(integrations=[RqIntegration()])

    events = capture_events_forksafe()

    queue = rq.Queue(connection=FakeStrictRedis())
    worker = rq.Worker([queue], connection=queue.connection)

    queue.enqueue(crashing_job, foo=42)
    worker.work(burst=True)

    event = events.read_event()
    events.read_flush()

    (exception,) = event["exception"]["values"]
    assert exception["type"] == "ZeroDivisionError" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:18,代码来源:test_rq.py

示例2: get_worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def get_worker(self, listen=()):
        if not listen:
            listen = self.config["queues"]

        def send_to_sentry(job, *exc_info):
            self.sentry.captureException(
                exc_info=exc_info,
                extra={
                    "job_id": job.id,
                    "func": job.__name__,
                    "args": job.args,
                    "kwargs": job.kwargs,
                    "description": job.description,
                },
            )

        exception_handlers = [send_to_sentry]

        return Worker(
            [QueueType(k, connection=self.connection) for k in listen],
            exception_handlers=exception_handlers,
            connection=self.connection,
        ) 
开发者ID:getsentry,项目名称:freight,代码行数:25,代码来源:queue.py

示例3: _calc_rq_free

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def _calc_rq_free() -> Dict[str, Any]:
    """Parses the output of `rq info` to return total number
    of workers and the count of workers currently idle."""

    conn = default_redis_conn()
    with rq.Connection(connection=conn):
        workers: List[rq.Worker] = [w for w in rq.Worker.all()]
    idle_workers = [w for w in workers if w.get_state() == 'idle']
    resp = {
        'workersTotal': len(workers),
        'workersIdle': len(idle_workers),
        'workersUnknown': len([w for w in workers if w.get_state() == '?'])
    }
    queues = 'default', 'build', 'publish'
    resp.update({f'queue{q.capitalize()}Size':
                 len(rq.Queue(f'gigantum-{q}-queue', connection=conn)) for q in queues})
    return resp 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:19,代码来源:telemetry.py

示例4: run_worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def run_worker():
    redis_url = app.config['REDIS_URL']
    redis_connection = redis.from_url(redis_url)
    with Connection(redis_connection):
        worker = Worker(app.config['QUEUES'])
        worker.work() 
开发者ID:mjhea0,项目名称:flask-spark-docker,代码行数:8,代码来源:manage.py

示例5: runworker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def runworker(app):

    REDIS_HOST = app.config['REDIS_HOST']
    REDIS_PORT = app.config['REDIS_PORT']
    REDIS_DB = app.config['REDIS_DB']
    QUEUES = app.config['QUEUES']

    redis_conn = Connection(Redis(REDIS_HOST,
                                  REDIS_PORT,
                                  REDIS_DB))
    with redis_conn:
        w = Worker(QUEUES)
        w.work() 
开发者ID:reiinakano,项目名称:xcessiv,代码行数:15,代码来源:runworker.py

示例6: run_worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def run_worker():
    redis_url = app.config["REDIS_URL"]
    redis_connection = redis.from_url(redis_url)
    with Connection(redis_connection):
        worker = Worker(app.config["QUEUES"])
        worker.work() 
开发者ID:mjhea0,项目名称:flask-redis-queue,代码行数:8,代码来源:manage.py

示例7: runworker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def runworker():
    redis_url = app.config['REDIS_URL']
    redis_connection = redis.from_url(redis_url)
    with Connection(redis_connection):
        worker = Worker(app.config['QUEUES'])
        worker.work() 
开发者ID:beenje,项目名称:flask-rq-example,代码行数:8,代码来源:manage.py

示例8: run_worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def run_worker():
    print("WORKING")
    worker = rq.Worker([queue], connection=queue.connection)
    worker.work() 
开发者ID:getsentry,项目名称:sentry-python,代码行数:6,代码来源:tracing.py

示例9: start

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def start(redis_connection, queues):
    with Connection(redis_connection):
        w = Worker(queues)
        w.work() 
开发者ID:columbia,项目名称:fairtest,代码行数:6,代码来源:worker.py

示例10: compensate

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def compensate(recruiter, worker_id, email, dollars, sandbox):
    """Credit a specific worker by ID through their recruiter"""
    out = Output()
    config = get_config()
    config.load()
    mode = "sandbox" if sandbox else "live"
    do_notify = email is not None
    no_email_str = "" if email else " NOT"

    with config.override({"mode": mode}):
        rec = by_name(recruiter)
        if not click.confirm(
            '\n\nYou are about to pay worker "{}" ${:.2f} in "{}" mode using the "{}" recruiter.\n'
            "The worker will{} be notified by email. "
            "Continue?".format(worker_id, dollars, mode, recruiter, no_email_str)
        ):
            out.log("Aborting...")
            return

        try:
            result = rec.compensate_worker(
                worker_id=worker_id, email=email, dollars=dollars, notify=do_notify
            )
        except Exception as ex:
            out.error(
                "Compensation failed. The recruiter reports the following error:\n{}".format(
                    ex
                ),
                delay=0,
            )
            return

    out.log("HIT Details", delay=0)
    out.log(tabulate.tabulate(result["hit"].items()), chevrons=False, delay=0)
    out.log("Qualification Details", delay=0)
    out.log(tabulate.tabulate(result["qualification"].items()), chevrons=False, delay=0)
    out.log("Worker Notification", delay=0)
    out.log(tabulate.tabulate(result["email"].items()), chevrons=False, delay=0) 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:40,代码来源:command_line.py

示例11: rq_worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def rq_worker():
    """Start an rq worker in the context of dallinger."""
    setup_experiment(log)
    with Connection(redis_conn):
        # right now we care about low queue for bots
        worker = Worker("low")
        worker.work() 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:9,代码来源:command_line.py

示例12: worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def worker():
    logging.info('this is worker')
    with Connection(conn):
        worker = Worker(map(Queue, listen))
        worker.work() 
开发者ID:rfyiamcool,项目名称:swift_rpc,代码行数:7,代码来源:multi_rqworker.py

示例13: worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def worker(queue_list):
    """Creates worker object."""

    def build_worker():
        """Build worker."""
        log_level = os.getenv('RQ_WORKER_LOG_LEVEL', 'WARNING')
        setup_loghandlers(log_level)
        log.info('worker log level set to {}'.format(log_level))

        rq_worker = Worker(queue_list, connection=WorkerQueues.connection)
        log.info('worker created')

        return rq_worker

    yield build_worker() 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:17,代码来源:worker.py

示例14: handle

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def handle(self, *args, **options):
        redis_conn = django_rq.get_connection('default')
        
        q = Queue(settings.DJANGO_TEST_RQ_LOW_QUEUE, connection=redis_conn)
        worker = Worker([q], exc_handler=my_handler, connection=redis_conn)
        worker.work() 
开发者ID:spapas,项目名称:django-test-rq,代码行数:8,代码来源:custom_worker.py

示例15: start_worker

# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def start_worker(queue_name):
    print "starting worker '{}'...".format(queue_name)

    with Connection(redis_rq_conn):
        worker = Worker(Queue(queue_name), exc_handler=failed_job_handler)
        worker.work() 
开发者ID:ourresearch,项目名称:depsy,代码行数:8,代码来源:rq_worker.py


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