Exemplo n.º 1
0
    def test_wr(self):

        c = comm.Comm(host=self.server, port=self.port)
        
        c.publish(comm.pack(self.data_struct))        
        c.subscribe(recv_cb)
        
        c.disconnect('network_consumer')
Exemplo n.º 2
0
Arquivo: agent.py Projeto: safl/levis
    def output_handler(self):
        """
        Communication, send RPC results and error events.
        """

        while self.running:
            try:
                res = (device_id, task, task_res) = self.output_queue.get(True, 1)  # Grab output from output queue

                method_name   = 'Unknown'
                if 'method' in task:
                    method_name = task['method']

                if 'name' in task:
                    name = task['name']
                else:
                    name = method_name

                invocation_id = None
                if 'id' in task:
                    invocation_id = task['id']
                
                # Check for errors during execution
                (rc, err, out) = (None, None, None)
                try:
                    (rc, err, out) = task_res
                except:
                    logging.debug('OUTPUT-FORMAT-ERROR %s.' % repr(task_res))

                if err:
                    message = comm.pack(comm.rpc_error(rc, err, invocation_id, self.agent_conf['agent_id'], device_id))
                else:
                    message = comm.pack(comm.rpc_response(task_res, invocation_id, self.agent_conf['agent_id'], device_id))

                #publish_tube = "%s-%s" % (self.output_tube, name)
                logging.debug(comm.rpc_response(task_res, invocation_id, self.agent_conf['agent_id'], device_id))
                publish_tube = "%s-%s" % (self.output_tube, method_name)
                logging.debug('Publishing to [%s]...' % publish_tube)
                
                self.publish(message, publish_tube)

            except Queue.Empty:
                pass
            except:
                logging.debug('Noller!', exc_info=3)