Example #1
0
    def registerController(self, controllernode):
        '''
            register to controller. 

            first, call *register* in controller,
            then:
            if the procedure was running successfully,
                we will return the message in data.
            if there happened a exception,
                we will return a None.
        '''
        message = None
        try:
            data = yield controllernode.callRemote(
                'register',
                self.servicename,
                self.version_major,
                self.version_minor,
                self.host_name,
                self.node,
            )
            message, clientid = data
            self.clientid = clientid
            self.controller = controllernode
            self.ready = True
        except:
            log.error("Error when register to controller.")
            log.exception()
            self._clearController()

        returnValue(message)
Example #2
0
    def registerController(self, controllernode):
        '''
            register to controller. 

            first, call *register* in controller,
            then:
            if the procedure was running successfully,
                we will return the message in data.
            if there happened a exception,
                we will return a None.
        '''
        message = None
        try:
            data = yield controllernode.callRemote(
                'register',
                self.servicename,
                self.version_major,
                self.version_minor,
                self.host_name,
                self.node,
            )
            message, clientid = data
            self.clientid = clientid
            self.controller = controllernode
            self.ready = True
        except:
            log.error("Error when register to controller.")
            log.exception()
            self._clearController()

        returnValue(message)
Example #3
0
 def procLoop(self):
     ''' main function '''
     while True:
         req_id, method, args, kwargs = yield self.controllerPull()
         try:
             m = getattr(self, method)
             result = yield m(*args, **kwargs)
             yield self.controllerReturn(req_id, {'result': result})
         except:
             log.exception()
             exctype, value, traceback = sys.exc_info()
             yield self.controllerReturn(
                 req_id,
                 {'error': {
                     'type': exctype,
                     'value': value,
                     'traceback': traceback,
                 }},
             )
Example #4
0
 def procLoop(self):
     ''' main function '''
     while True:
         req_id, method, args, kwargs = yield self.controllerPull()
         try:
             m = getattr(self, method)
             result = yield m(*args, **kwargs)
             yield self.controllerReturn(req_id, {'result': result})
         except:
             log.exception()
             exctype, value, traceback = sys.exc_info()
             yield self.controllerReturn(
                 req_id,
                 {
                     'error': {
                         'type': exctype,
                         'value': value,
                         'traceback': traceback,
                     }
                 },
             )
Example #5
0
    def searchLoop(self, agent):
        ''' '''
        needbreak = False
        while 1:
            result = None
            if agent.remove:
                self.agent_pool.removeAgent(agent)
                break

            reqid, task = yield self.callController('nextRequest', 'extract')
            log.info(repr(task))

            try:
                result = yield self.search(agent, task)
                log.debug('Got data %s' % repr(result))
            except InfiniteLoginError:
                log.exception()
                yield self.callController("fail", task=task)
                needbreak = True
            except:
                log.exception()
            self.callController('sendResult', reqid, task, json.dumps(result))
            if needbreak:
                break
Example #6
0
    def searchLoop(self, agent):
        ''' '''
        needbreak = False
        while 1:
            result = None
            if agent.remove:
                self.agent_pool.removeAgent(agent)
                break

            reqid, task = yield self.callController('nextRequest', 'data')
            log.info('Got Task %s with reqid: %s' % (repr(task), reqid))

            try:
                result = yield self.search(agent, task)
                log.debug('Got data %s' % repr(result))
            except InfiniteLoginError:
                log.exception()
                yield self.callController("fail", task=task)
                needbreak = True
            except:
                log.exception()
            self.callController('sendResult', reqid, task, json.dumps(result))
            if needbreak:
                break
Example #7
0
 def gotError(self, fail, tid):
     ''' 当出现异常时,将任务重新写入到Redis队列 '''
     log.exception(fail)
Example #8
0
 def gotError(self, fail, tid):
     ''' 当出现异常时,将任务重新写入到Redis队列 '''
     log.exception(fail)