예제 #1
0
    def emit(self, tup, stream=None, anchors=[], direct_task=None):
        """Emit a new tuple to a stream.

        :param tup: a ``list`` representing the tuple to send to Storm, should
        contain only JSON-serializable data.
        :param stream: a ``str`` indicating the ID of the stream to emit this
        tuple to. Specify ``None`` to emit to default stream.
        :param anchors: a ``list`` of IDs of the tuples tuple should be
        anchored to.
        :param direct_task: an ``int`` which indicates the task to send the
        tuple to.
        """
        if not isinstance(tup, list):
            raise TypeError('All tuples must be lists, received {!r} instead'
                            .format(type(tup)))
        if _ANCHOR_TUPLE is not None:
            anchors = [_ANCHOR_TUPLE]
        msg = {'command': 'emit', 'tuple': tup}
        if stream is not None:
            msg['stream'] = stream
        msg['anchors'] = [x.id for x in anchors]
        if direct_task is not None:
            msg['task'] = direct_task

        send_message(msg)
예제 #2
0
    def log(self, message, level='info'):
        """Log a message to Storm optionally providing a logging level.

        :param message: any object that supports ``__str__()``.
        :param level: a ``str`` representing the log level.
        """
        send_message({'command': 'log', 'msg': str(message), 'level': level})
예제 #3
0
    def emit(self, tup, stream=None, anchors=[], direct_task=None):
        """Emit a new tuple to a stream.

        :param tup: the Tuple payload to send to Storm, should contain only
                    JSON-serializable data.
        :type tup: list
        :param stream: the ID of the stream to emit this tuple to. Specify
                       ``None`` to emit to default stream.
        :type stream: str
        :param anchors: IDs of the tuples the emitted tuple should be anchored
                        to.
        :type anchors: list
        :param direct_task: the task to send the tuple to.
        :type direct_task: int
        """
        if not isinstance(tup, list):
            raise TypeError('All tuples must be lists, received {!r} instead'
                            .format(type(tup)))
        msg = {'command': 'emit', 'tuple': tup}
        if stream is not None:
            msg['stream'] = stream
        msg['anchors'] = [x.id for x in anchors]
        if direct_task is not None:
            msg['task'] = direct_task

        send_message(msg)
예제 #4
0
    def emit(self, tup, tup_id=None, stream=None, direct_task=None):
        """Emit a spout tuple message.

        :param tup: a ``list`` representing the tuple to send to Storm.  Should
        contain only JSON-serializable data.
        :param tup_id: ``str`` or ``int`` which is the id for the tuple. Leave
        this blank for an unreliable emit.
        :param stream: ``str`` ID of the stream this tuple should be emitted
        to.  Leave empty to emit to the default stream.
        :param direct_task: ``int`` indicating the task to send the tuple to if
        performing a direct emit.
        """
        if not isinstance(tup, list):
            raise TypeError(
                'All tuples must be lists, received {!r} instead'.format(
                    type(tup)))

        msg = {'command': 'emit', 'tuple': tup}
        if tup_id is not None:
            msg['id'] = tup_id
        if stream is not None:
            msg['stream'] = stream
        if direct_task is not None:
            msg['task'] = direct_task

        send_message(msg)
예제 #5
0
    def log(self, message, level='info'):
        """Log a message to Storm optionally providing a logging level.

        :param message: any object that supports ``__str__()``.
        :param level: a ``str`` representing the log level.
        """
        send_message({'command': 'log', 'msg': str(message), 'level': level})
예제 #6
0
파일: funcs.py 프로젝트: sgricci/digsby
def handle_ipc_action():
    '''Looks for --action=foo on the command line, and sends an IPC message to
    a running Digsby instance.'''
    if sys.opts.action:
        import ipc
        ipc.send_message(sys.opts.action)
        return True
예제 #7
0
    def emit(self, tup, tup_id=None, stream=None, direct_task=None):
        """Emit a spout tuple message.

        :param tup: a ``list`` representing the tuple to send to Storm.  Should
        contain only JSON-serializable data.
        :param tup_id: ``str`` or ``int`` which is the id for the tuple. Leave
        this blank for an unreliable emit.
        :param stream: ``str`` ID of the stream this tuple should be emitted
        to.  Leave empty to emit to the default stream.
        :param direct_task: ``int`` indicating the task to send the tuple to if
        performing a direct emit.
        """
        if not isinstance(tup, list):
            raise TypeError('All tuples must be lists, received {!r} instead'
                            .format(type(tup)))

        msg = {'command': 'emit', 'tuple': tup}
        if tup_id is not None:
            msg['id'] = tup_id
        if stream is not None:
            msg['stream'] = stream
        if direct_task is not None:
            msg['task'] = direct_task

        send_message(msg)
예제 #8
0
    def fail(self, tup):
        """Indicate that processing of a tuple has failed.

        :param tup: the tuple to fail.
        :type tup: str or Tuple
        """
        tup_id = tup.id if isinstance(tup, Tuple) else tup
        send_message({'command': 'fail', 'id': tup_id})
예제 #9
0
    def ack(self, tup):
        """Indicate that processing of a tuple has succeeded.

        :param tup: the tuple to acknowledge.
        :type tup: str or Tuple
        """
        tup_id = tup.id if isinstance(tup, Tuple) else tup
        send_message({'command': 'ack', 'id': tup_id})
예제 #10
0
def handle_ipc_action():
    """Looks for --action=foo on the command line, and sends an IPC message to
    a running Digsby instance."""
    if sys.opts.action:
        import ipc

        ipc.send_message(sys.opts.action)
        return True
예제 #11
0
    def log(self, message, level='info'):
        """Log a message to Storm optionally providing a logging level.

        :param message: the log message to send to Storm.
        :type message: str
        :param level: the logging level that Storm should use when writing the
                      ``message``.
        :type level: str
        """
        send_message({'command': 'log', 'msg': str(message), 'level': level})
예제 #12
0
    def raise_exception(self, exception, tup=None):
        """Report an exception back to Storm via logging.

        :param exception: a Python exception.
        :param tup: a :class:`Tuple` object.
        """
        if tup:
            message = ('Python {exception_name} raised while processing tuple '
                       '{tup!r}\n{traceback}')
        else:
            message = 'Python {exception_name} raised\n{traceback}'
        message = message.format(exception_name=exception.__class__.__name__,
                                 tup=tup,
                                 traceback=traceback.format_exc(exception))
        self.log(message)
        send_message({'command': 'sync'})  # sync up right away
예제 #13
0
    def raise_exception(self, exception, tup=None):
        """Report an exception back to Storm via logging.

        :param exception: a Python exception.
        :param tup: a :class:`Tuple` object.
        """
        if tup:
            message = ('Python {exception_name} raised while processing tuple '
                       '{tup!r}\n{traceback}')
        else:
            message = 'Python {exception_name} raised\n{traceback}'
        message = message.format(exception_name=exception.__class__.__name__,
                                 tup=tup,
                                 traceback=traceback.format_exc(exception))
        self.log(message)
        send_message({'command': 'sync'})  # sync up right away
예제 #14
0
 def run(self):
     """Main run loop for all spouts. Performs initial handshake with Storm
     and reads tuples handing them off to subclasses.  Any exceptions are
     caught and logged back to Storm prior to the Python process exits.
     Subclasses should not override this method.
     """
     storm_conf, context = read_handshake()
     try:
         self.initialize(storm_conf, context)
         while True:
             cmd = read_command()
             if cmd['command'] == 'next':
                 self.next_tuple()
             if cmd['command'] == 'ack':
                 self.ack(cmd['id'])
             if cmd['command'] == 'fail':
                 self.fail(cmd['id'])
             send_message({'command': 'sync'})
     except Exception as e:
         self.raise_exception(e)
예제 #15
0
 def run(self):
     """Main run loop for all spouts. Performs initial handshake with Storm
     and reads tuples handing them off to subclasses.  Any exceptions are
     caught and logged back to Storm prior to the Python process exits.
     Subclasses should not override this method.
     """
     storm_conf, context = read_handshake()
     try:
         self.initialize(storm_conf, context)
         while True:
             cmd = read_command()
             if cmd['command'] == 'next':
                 self.next_tuple()
             if cmd['command'] == 'ack':
                 self.ack(cmd['id'])
             if cmd['command'] == 'fail':
                 self.fail(cmd['id'])
             send_message({'command': 'sync'})
     except Exception as e:
         self.raise_exception(e)
예제 #16
0
    def fail(self, tup):
        """Indicate that processing of a tuple has failed.

        :param tup: a :class:`base.Tuple` object.
        """
        send_message({'command': 'fail', 'id': tup.id})
예제 #17
0
    def ack(self, tup):
        """Indicate that processing of a tuple has succeeded.

        :param tup: a :class:`base.Tuple` object.
        """
        send_message({'command': 'ack', 'id': tup.id})