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


Python events.EventReceiver类代码示例

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


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

示例1: main

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()
开发者ID:bmbouter,项目名称:CeleryManagement,代码行数:27,代码来源:cmevdump.py

示例2: eventtop

def eventtop():
    sys.stderr.write("-> celeryev: 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:
        consumer = recv.consumer()
        consumer.consume()
        while True:
            try:
                conn.connection.drain_events()
            except socket.timeout:
                pass
    except Exception:
        refresher.shutdown = True
        refresher.join()
        display.resetscreen()
        raise
    except (KeyboardInterrupt, SystemExit):
        conn and conn.close()
        refresher.shutdown = True
        refresher.join()
        display.resetscreen()
开发者ID:HonzaKral,项目名称:celery,代码行数:27,代码来源:celeryev.py

示例3: run

    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)
开发者ID:ZoeGeng,项目名称:Art,代码行数:25,代码来源:events.py

示例4: evcam

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()
开发者ID:berg,项目名称:celery,代码行数:25,代码来源:snapshot.py

示例5: evdump

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()
开发者ID:clayg,项目名称:celery,代码行数:9,代码来源:dumper.py

示例6: evdump

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()
开发者ID:berg,项目名称:celery,代码行数:10,代码来源:dumper.py

示例7: celery_listener

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)
开发者ID:gnowxilef,项目名称:create,代码行数:55,代码来源:ircbot.py

示例8: EventListener

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()
开发者ID:Kami,项目名称:celerymon,代码行数:11,代码来源:listener.py

示例9: CeleryConsumer

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()
开发者ID:brandedme,项目名称:librato,代码行数:14,代码来源:__init__.py

示例10: run

    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)
开发者ID:MechanisM,项目名称:flower,代码行数:17,代码来源:events.py

示例11: run

 def run(self):
     with self.celery.connection() as conn:
         self.receiver = EventReceiver(
             conn,
             handlers={'*': self.state.event},
             app=self.celery,
         )
         self.receiver.capture()
开发者ID:brandedme,项目名称:librato,代码行数:8,代码来源:__init__.py

示例12: MonitorListener

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()
开发者ID:vbabiy,项目名称:celerymon,代码行数:18,代码来源:service.py

示例13: run

    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)
开发者ID:Crowdbooster,项目名称:flower,代码行数:18,代码来源:events.py

示例14: MonitorListener

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()
开发者ID:thegreatape,项目名称:celerymon,代码行数:20,代码来源:service.py

示例15: __init__

 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,
     })
开发者ID:vbabiy,项目名称:celerymon,代码行数:12,代码来源:service.py


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