本文整理汇总了Python中celery.events.EventReceiver.capture方法的典型用法代码示例。如果您正苦于以下问题:Python EventReceiver.capture方法的具体用法?Python EventReceiver.capture怎么用?Python EventReceiver.capture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.events.EventReceiver
的用法示例。
在下文中一共展示了EventReceiver.capture方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evcam
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def evcam(camera, freq=1.0, maxrate=None, loglevel=0,
logfile=None, app=None):
app = app_or_default(app)
if not isinstance(loglevel, int):
loglevel = LOG_LEVELS[loglevel.upper()]
logger = app.log.setup_logger(loglevel=loglevel,
logfile=logfile,
name="celery.evcam")
logger.info(
"-> evcam: Taking snapshots with %s (every %s secs.)\n" % (
camera, freq))
state = State()
cam = instantiate(camera, state, app=app,
freq=freq, maxrate=maxrate, logger=logger)
cam.install()
conn = app.broker_connection()
recv = EventReceiver(conn, app=app, handlers={"*": state.event})
try:
try:
recv.capture(limit=None)
except KeyboardInterrupt:
raise SystemExit
finally:
cam.cancel()
conn.close()
示例2: main
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def main():
def print_event(event):
type = event.pop("type")
s = "Event: {0}\n".format(type)
keys = event.keys()
keys.sort()
for k in keys:
v = event[k]
s += " {0}: {1}\n".format(k, v)
print s
print "Initializing event listener."
app = app_or_default(None)
conn = app.broker_connection()
recv = EventReceiver(conn, handlers={"*": print_event}, app=app)
try:
try:
print "Listening for events... (use Ctrl-C to exit)"
recv.capture(limit=None)
except KeyboardInterrupt, SystemExit:
raise SystemExit
except Exception:
import traceback
print "Exception while listening for events:\n"
traceback.print_exc()
示例3: run
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def run(self):
try_interval = 1
while True:
try:
try_interval *= 2
with self.capp.connection() as conn:
recv = EventReceiver(conn,
handlers={"*": self.on_event},
app=self.capp)
try_interval = 1
recv.capture(limit=None, timeout=None, wakeup=True)
except (KeyboardInterrupt, SystemExit):
try:
import _thread as thread
except ImportError:
import thread
thread.interrupt_main()
except Exception as e:
logger.error("Failed to capture events: '%s', "
"trying again in %s seconds.",
e, try_interval)
logger.debug(e, exc_info=True)
time.sleep(try_interval)
示例4: celery_listener
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def celery_listener(uri):
"""Listen for events from Celery, relay to IRC."""
connection = Connection(uri)
def on_account_created(event):
request = event['request']
bot_announce(
IRC_CHANNELS_ANNOUNCE,
'{user} created ({real_name})'.format(
user=request['user_name'],
real_name=request['real_name'],
),
)
def on_account_submitted(event):
request = event['request']
bot_announce(
IRC_CHANNELS,
'{user} ({real_name}) needs approval: {reasons}'.format(
user=request['user_name'],
real_name=request['real_name'],
reasons=', '.join(request['reasons']),
),
)
def on_account_approved(event):
request = event['request']
bot_announce(
IRC_CHANNELS_ANNOUNCE,
'{user} was approved, now pending creation.'.format(
user=request['user_name'],
),
)
def on_account_rejected(event):
request = event['request']
bot_announce(
IRC_CHANNELS_ANNOUNCE,
'{user} was rejected.'.format(
user=request['user_name'],
),
)
while True:
with connection as conn:
recv = EventReceiver(
conn,
handlers={
'ocflib.account_created': on_account_created,
'ocflib.account_submitted': on_account_submitted,
'ocflib.account_approved': on_account_approved,
'ocflib.account_rejected': on_account_rejected,
},
)
recv.capture(limit=None, timeout=None)
示例5: evdump
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def evdump():
sys.stderr.write("-> evdump: starting capture...\n")
dumper = Dumper()
conn = establish_connection()
recv = EventReceiver(conn, handlers={"*": dumper.on_event})
try:
recv.capture()
except (KeyboardInterrupt, SystemExit):
conn and conn.close()
示例6: evdump
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def evdump(app=None):
sys.stderr.write("-> evdump: starting capture...\n")
app = app_or_default(app)
dumper = Dumper()
conn = app.broker_connection()
recv = EventReceiver(conn, app=app, handlers={"*": dumper.on_event})
try:
recv.capture()
except (KeyboardInterrupt, SystemExit):
conn and conn.close()
示例7: EventListener
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
class EventListener(object):
"""Capture events sent by messages and store them in memory."""
def __init__(self, state=state):
self.state = state
self.connection = establish_connection()
self.receiver = EventReceiver(self.connection,
handlers={"*": self.state.event})
def start(self):
self.receiver.capture()
示例8: CeleryConsumer
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
class CeleryConsumer(Thread):
def __init__(self, state, celery):
super(CeleryConsumer, self).__init__()
self.celery = celery
self.state = state
def run(self):
with self.celery.connection() as conn:
self.receiver = EventReceiver(
conn,
handlers={'*': self.state.event},
app=self.celery,
)
self.receiver.capture()
示例9: run
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def run(self):
logging.info("Enabling events")
celery.control.enable_events()
while True:
try:
with establish_connection() as connection:
recv = EventReceiver(
connection, handlers={"*": state.event})
with DumpCam(state, freq=1.0):
recv.capture(limit=None, timeout=None)
except (KeyboardInterrupt, SystemExit):
import thread
thread.interrupt_main()
except Exception as e:
logging.error("An error occurred while capturing events"
": %s" % e)
示例10: MonitorListener
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
class MonitorListener(object):
"""Capture events sent by messages and store them in memory."""
def __init__(self, state):
self.connection = DjangoBrokerConnection()
self.receiver = EventReceiver(self.connection, handlers={
"task-received": state.receive_task_received,
"task-accepted": state.receive_task_event,
"task-succeeded": state.receive_task_event,
"task-retried": state.receive_task_event,
"task-failed": state.receive_task_event,
"worker-online": state.receive_worker_event,
"worker-offline": state.receive_worker_event,
"worker-heartbeat": state.receive_heartbeat,
})
def start(self):
self.receiver.capture()
示例11: run
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def run(self):
try_interval = 1
while True:
try:
try_interval *= 2
with self._celery_app.connection() as conn:
recv = EventReceiver(conn, handlers={"*": self.on_event}, app=self._celery_app)
recv.capture(limit=None, timeout=None)
try_interval = 1
except (KeyboardInterrupt, SystemExit):
import thread
thread.interrupt_main()
except Exception as e:
logging.error("Failed to capture events: '%s', " "trying again in %s seconds." % (e, try_interval))
time.sleep(try_interval)
示例12: MonitorListener
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
class MonitorListener(threading.Thread):
"""Capture events sent by messages and store them in memory."""
def __init__(self, state, *args, **kwargs):
super(MonitorListener, self).__init__(*args, **kwargs)
self.connection = DjangoBrokerConnection()
self.receiver = EventReceiver(self.connection, handlers={
"task-received": state.receive_task_received,
"task-accepted": state.receive_task_event,
"task-succeeded": state.receive_task_event,
"task-retried": state.receive_task_event,
"task-failed": state.receive_task_event,
"worker-online": state.receive_worker_event,
"worker-offline": state.receive_worker_event,
"worker-heartbeat": state.receive_heartbeat,
})
self.setDaemon(True)
def run(self):
self.receiver.capture()
示例13: evtop
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def evtop():
sys.stderr.write("-> evtop: starting capture...\n")
state = State()
display = CursesMonitor(state)
display.init_screen()
refresher = DisplayThread(display)
refresher.start()
conn = establish_connection()
recv = EventReceiver(conn, handlers={"*": state.event})
try:
recv.capture(limit=None)
except Exception:
refresher.shutdown = True
refresher.join()
display.resetscreen()
raise
except (KeyboardInterrupt, SystemExit):
conn and conn.close()
refresher.shutdown = True
refresher.join()
display.resetscreen()
示例14: my_monitor
# 需要导入模块: from celery.events import EventReceiver [as 别名]
# 或者: from celery.events.EventReceiver import capture [as 别名]
def my_monitor():
connection = BrokerConnection('amqp://guest:[email protected]:5672//')
import json
def on_task_succeeded(event):
#print "TASK SUCCEEDED! ", event
result = event['result']
#print "RESULT: ", result
#result = json.loads(result)
# print "RESULT --------------------------", result, " and TYPE OF RESULTTTTTTTTTTTTTTTTTTTTTTTTTTT", type(result)
# print "SUBMISSION ID:------------------------------", result['submission_id']
# url_str = build_url(result['submission_id'], result['file_id'])
# response = requests.put(url_str, data=serialize(result), headers={'Content-Type' : 'application/json'})
# print "SENT PUT REQUEST. RESPONSE RECEIVED: ", response
##
def on_task_failed(event):
#print "TASK FAILED!", event
exception = event['exception']
def on_update(event):
#print "TASK UPDATE!!!!!", event
result = event['result']
#print "TYPE OF RESULT IN UPDATE CASEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", type(result)
# url_str = build_url(result['submission_id'], result['file_id'])
# response = requests.put(url_str, data=serialize(result), headers={'Content-Type' : 'application/json'})
# print "SENT PUT REQUEST. RESPONSE RECEIVED: ", response
def on_event(event):
#print "EVENT HAPPENED: ", event
pass
def on_custom(event):
#print "EVENT TYPE: ", event['type']
#if event['type'] != "worker-heartbeat":
print "CUSTOM - TASK!", event
def on_worker_online(event):
print "worker came onlineeeeee!!! Event: ", str(event)
#try_interval = 3
while True:
try:
#try_interval *= 2
with connection as conn:
recv = EventReceiver(conn,
handlers={'task-failed' : on_task_failed,
'task-succeeded' : on_task_succeeded,
'task-sent' : on_event,
'task-received' : on_event,
'task-revoked' : on_event,
'task-retried' : on_event,
'task-started' : on_event,
'task-update' : on_update,
'worker-online' : on_worker_online
#'task-update' : on_custom,
#'*' : on_custom
})
#handlers={'*': on_event})
#print "PRINT FROM Monitor: ", ( vars(recv.consumer) )
recv.capture(limit=None, timeout=None)
#try_interval = 3
except (KeyboardInterrupt, SystemExit):
print "EXCEPTION KEYBOARD INTERRUPT"
sys.exit()