예제 #1
0
 async def handle_heartbeat(self, **kwargs):
     results = kwargs.pop('results', [])
     for agent in await self.get_service('data_svc').locate(
             'agents', dict(paw=kwargs.get('paw', None))):
         await agent.heartbeat_modification(**kwargs)
         self.log.debug('Incoming %s beacon from %s' %
                        (agent.contact, agent.paw))
         for result in results:
             await self._save(Result(**result))
             await self.get_service('event_svc').fire_event(
                 'link/completed', agent=agent.display, pid=result['pid'])
         return agent, await self._get_instructions(agent)
     agent = await self.get_service('data_svc').store(
         Agent.load(
             dict(sleep_min=self.get_config(name='agents',
                                            prop='sleep_min'),
                  sleep_max=self.get_config(name='agents',
                                            prop='sleep_max'),
                  watchdog=self.get_config(name='agents', prop='watchdog'),
                  **kwargs)))
     await self._add_agent_to_operation(agent)
     self.log.debug('First time %s beacon from %s' %
                    (agent.contact, agent.paw))
     await agent.bootstrap(self.get_service('data_svc'))
     return agent, await self._get_instructions(agent)
예제 #2
0
 async def handle_heartbeat(self, **kwargs):
     results = kwargs.pop('results', [])
     old_paw = kwargs.get('paw')
     if old_paw:
         kwargs['paw'] = await self._sanitize_paw(old_paw)
     for agent in await self.get_service('data_svc').locate('agents', dict(paw=kwargs.get('paw', None))):
         await agent.heartbeat_modification(**kwargs)
         self.log.debug('Incoming %s beacon from %s' % (agent.contact, agent.paw))
         for result in results:
             self.log.debug('Received result for link %s from agent %s via contact %s' % (result['id'], agent.paw,
                                                                                          agent.contact))
             await self._save(Result(**result))
             operation = await self.get_service('app_svc').find_op_with_link(result['id'])
             access = operation.access if operation else self.Access.RED
             await self.get_service('event_svc').fire_event(exchange='link', queue='completed', agent=agent.display,
                                                            pid=result['pid'], link_id=result['id'],
                                                            access=access.value)
         if results:
             return agent, []
         return agent, await self._get_instructions(agent)
     agent = await self.get_service('data_svc').store(
         Agent.load(dict(sleep_min=self.get_config(name='agents', prop='sleep_min'),
                         sleep_max=self.get_config(name='agents', prop='sleep_max'),
                         watchdog=self.get_config(name='agents', prop='watchdog'),
                         **kwargs))
     )
     await self._add_agent_to_operation(agent)
     self.log.debug('First time %s beacon from %s' % (agent.contact, agent.paw))
     data_svc = self.get_service('data_svc')
     await agent.bootstrap(data_svc)
     if agent.deadman_enabled:
         self.log.debug("Agent %s can accept deadman abilities. Will return any available deadman abilities." %
                        agent.paw)
         await agent.deadman(data_svc)
     return agent, await self._get_instructions(agent)