Example #1
0
    def monitor_events(self):
        """
        Process Celery events.

        Receives events from Celery and matches each with the appropriate handler function. The
        following events are monitored for: 'task-failed', 'task-succeeded', 'worker-heartbeat',
        and 'worker-offline'. The call to capture() is blocking, and does not return.

        Capture is called with wakeup=True causing a gratuitous 'worker-heartbeat' to be sent
        from all workers. This should handle the case of worker discovery where workers already
        exist, and this EventMonitor is started afterwards.

        The call to capture is wrapped in a log-but-continue try/except statement, which along
        with the loop will cause the capture method to be re-entered.
        """
        with app.connection() as connection:
            recv = app.events.Receiver(
                connection,
                handlers={
                    'worker-heartbeat': worker_watcher.handle_worker_heartbeat,
                    'worker-offline': worker_watcher.handle_worker_offline,
                    'worker-online': worker_watcher.handle_worker_heartbeat,
                })
            _logger.info(_('Event Monitor Starting'))
            recv.capture(limit=None, timeout=None, wakeup=True)
Example #2
0
    def monitor_events(self):
        """
        Process celery events.

        Receives events from celery and matches each with the appropriate handler function. The
        following events are monitored for: 'task-failed', 'task-succeeded', 'worker-heartbeat',
        and 'worker-offline'. The call to capture() is blocking, and does not return.

        Capture is called with wakeup=True causing a gratuitous 'worker-heartbeat' to be sent
        from all workers. This should handle the case of worker discovery where workers already
        exist, and this EventMonitor is started afterwards.

        The call to capture is wrapped in a log-but-continue try/except statement, which along
        with the loop will cause the capture method to be re-entered.
        """
        with app.connection() as connection:
            recv = app.events.Receiver(connection, handlers={
                'task-failed': self._failure_watcher.handle_failed_task,
                'task-succeeded': self._failure_watcher.handle_succeeded_task,
                'worker-heartbeat': worker_watcher.handle_worker_heartbeat,
                'worker-offline': worker_watcher.handle_worker_offline,
                'worker-online': worker_watcher.handle_worker_heartbeat,
            })
            _logger.info(_('Event Monitor Starting'))
            recv.capture(limit=None, timeout=None, wakeup=True)
Example #3
0
 def monitor_events(self):
     """
     Receives events from celery and matches each with the appropriate
     handler function. This will not return, and thus should be called in
     its own thread.
     """
     with app.connection() as connection:
         recv = app.events.Receiver(connection, handlers={
             'task-failed': self.handle_failed_task,
             'task-succeeded': self.handle_succeeded_task,
         })
         recv.capture(limit=None, timeout=None, wakeup=False)
Example #4
0
def get_broker_conn_status():
    """
    :returns:          message broker connection status
    :rtype:            bool
    """
    # not all drivers support heartbeats. For now, we need to make an
    # explicit connection and then release it.
    # See https://github.com/celery/kombu/issues/432 for more detail.
    try:
        conn = celery.connection()
        conn.connect()
        conn.release()
        return {'connected': True}
    except:
        # if the above was not successful for any reason, return False
        return {'connected': False}
Example #5
0
def get_broker_conn_status():
    """
    :returns:          message broker connection status
    :rtype:            bool
    """
    # not all drivers support heartbeats. For now, we need to make an
    # explicit connection and then release it.
    # See https://github.com/celery/kombu/issues/432 for more detail.
    try:
        conn = celery.connection()
        conn.connect()
        conn.release()
        return {'connected': True}
    except:
        # if the above was not successful for any reason, return False
        return {'connected': False}