def process_task(task): try: logging.info(f'New task assigned:\n {task}') util.process_task(task) logging.info("Task is done.") except Exception as e: logging.info(f"Task can't be completed, error occured: {str(e)}") server.send_to_endpoint('ERROR', { "hash": util.client_info['client_id'], "log": str(e) }) return
def target_func(self): while True: resp = server.send_to_endpoint('PING', {'hash': self.client_id}) if self._is_stop(resp): logging.info(f"Received stop command from server!") self.stop_task_signal.send(Signals.STOP_TASK) sleep(util.config['PING_INTVAL'])
def _process_task(self, task): try: logging.info(f'New task assigned:\n {task}') task_manager.process_task(task) logging.info("Task is done.") self.client_status.value = ClientStatus.IDLE except Exception as e: logging.info(f"Task can't be completed, error occured: {str(e)}") if self.debug: logging.info(traceback.format_exc()) server.send_to_endpoint( 'ERROR', { "hash": self.client_id, "log": f"Error: {str(e)} \n Task: {str(task)}." }) return
def run(self): try: Process.run(self) except ConnectionError as e: logging.info( f"Can't connect to server. Error message: \n {str(e)}\n Client is exiting..." ) if self.debug: logging.info(traceback.format_exc()) sys.exit(-1) except KeyError: logging.info( "Worker id is unknown, try running the client with the --reinit argument." ) if self.debug: logging.info(traceback.format_exc()) sys.exit(-1) except Exception as e: logging.info( f"Unhandled exception occured:\n{str(e)} \n Client is exiting..." ) server.send_to_endpoint('ERROR', { "hash": self.client_id, "log": f"Unhandled exception: {str(e)}" }) if self.debug: logging.info(traceback.format_exc()) sys.exit(-1) except KeyboardInterrupt: if self.debug: logging.info( f"[{self.name}] Keyboard interruption, process is exiting..." ) logging.info(traceback.format_exc()) sys.exit(0)
args = parser.parse_args() logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO) logging.info("Client started...") dwf_logging.get_versions() if args.reinit and os.path.isfile(server.HASH_PICKLE): os.remove(server.HASH_PICKLE) logging.info(f"Connecting to server \'{util.config['SERVER_URL']}\'") client_id, task = server.connect() logging.info(f"Client id: {client_id}") util.client_info['client_id'] = client_id try: if task: process_task(task) while (True): run(client_id) except KeyboardInterrupt: logging.info("Keyboard interruption, client is exiting...") server.send_to_endpoint('ERROR', { "hash": util.client_info['client_id'], "log": "Manual interruption." }) sys.exit(0)
except ConnectionError as e: logging.info(f"Can't connect to server. Error message: \n {str(e)}\n Client is exiting...") if args.debug: logging.info(traceback.format_exc()) sys.exit(-1) except KeyError: logging.info("Worker id is unknown, try running the client with the --reinit argument.") if args.debug: logging.info(traceback.format_exc()) sys.exit(-1) except Exception as e: logging.info(f"Unhandled exception occured:\n{str(e)} \n Client is exiting...") server.send_to_endpoint('ERROR', {"hash": client_id, "log": f"Unhandled exception: {str(e)}"}) if args.debug: logging.info(traceback.format_exc()) sys.exit(-1) except KeyboardInterrupt: logging.info("Keyboard interruption, client is exiting...") server.send_to_endpoint('ERROR', {"hash": client_id, "log": "Manual interruption."}) if args.debug: logging.info(traceback.format_exc()) sys.exit(0)