async def run_dealer(self): """ Run the agent """ self._logger.info("Agent started") self._backend_socket.connect(self._backend_addr) # Init Docker events watcher await self.init_watch_docker_events() # Init watcher pipe await self.init_watcher_pipe() # Tell the backend we are up and have `nb_sub_agents` threads available self._logger.info("Saying hello to the backend") await ZMQUtils.send( self._backend_socket, AgentHello(self._friendly_name, self._nb_sub_agents, self._containers)) # And then run the agent try: while True: socks = await self._poller.poll() socks = dict(socks) # New message from backend if self._backend_socket in socks: message = await ZMQUtils.recv(self._backend_socket) await self.handle_backend_message(message) # New docker event if self._docker_events_subscriber in socks: message = await ZMQUtils.recv( self._docker_events_subscriber) await self.handle_docker_event(message) # End of watcher pipe if self._killer_watcher_pull.get_pull_socket() in socks: message = await ZMQUtils.recv( self._killer_watcher_pull.get_pull_socket()) await self.handle_watcher_pipe_message(message) except asyncio.CancelledError: return except KeyboardInterrupt: return
async def run(self): """ Runs the agent. Answer to the requests made by the Backend. May raise an asyncio.CancelledError, in which case the agent should clean itself and restart completely. """ self._logger.info("Agent started") self.__backend_socket.connect(self.__backend_addr) # Tell the backend we are up and have `concurrency` threads available self._logger.info("Saying hello to the backend") await ZMQUtils.send(self.__backend_socket, AgentHello(self.__friendly_name, self.__concurrency, self.environments)) self.__last_ping = time.time() run_listen = self._loop.create_task(self.__run_listen()) self._loop.call_later(1, self._create_safe_task, self.__check_last_ping(run_listen)) await run_listen
async def run(self): """ Runs the agent. Answer to the requests made by the Backend. """ self._logger.info("Agent started") self.__backend_socket.connect(self.__backend_addr) # Tell the backend we are up and have `concurrency` threads available self._logger.info("Saying hello to the backend") await ZMQUtils.send(self.__backend_socket, AgentHello(self.__friendly_name, self.__concurrency, self.environments)) try: while True: message = await ZMQUtils.recv(self.__backend_socket) await self._handle_backend_message(message) except asyncio.CancelledError: return except KeyboardInterrupt: return
async def run_dealer(self): """ Run the agent """ self._logger.info("Agent started") self._backend_socket.connect(self._backend_addr) # Tell the backend we are up self._logger.info("Saying hello to the backend") await ZMQUtils.send( self._backend_socket, AgentHello(1, {"mcq": { "id": "mcq", "created": 0 }}, {})) # And then run the agent try: while True: message = await ZMQUtils.recv(self._backend_socket) await self.handle_backend_message(message) except asyncio.CancelledError: return except KeyboardInterrupt: return