本文整理汇总了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"
示例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,
)
示例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
示例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()
示例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()
示例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()
示例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()
示例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()
示例9: start
# 需要导入模块: import rq [as 别名]
# 或者: from rq import Worker [as 别名]
def start(redis_connection, queues):
with Connection(redis_connection):
w = Worker(queues)
w.work()
示例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)
示例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()
示例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()
示例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()
示例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()
示例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()