當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。