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