import time import logging from stat import S_ISREG from paramiko.ssh_exception import SSHException from report_ops.status import CitcoSubmission logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def close_and_reconnect(creds, folder): retries = 5 for i in range(retries): try: CitcoSubmission._client.client.close() CitcoSubmission.init_client(creds, folder=folder) except (SSHException, OSError) as e: if i == retries - 1: raise e else: time.sleep(60 * i) else: return def run(): while True: CitcoSubmission.init_client("citco", folder="/outgoing/notifications") try: for f in CitcoSubmission._client.client.listdir_iter( "/outgoing/notifications" ): if S_ISREG(f.st_mode): try: CitcoSubmission.process(f.filename) except ValueError as e: logger.info(f"{e}") except (SSHException, OSError) as e: logger.info(e) close_and_reconnect("citco", "/outgoing/notifications") time.sleep(60) CitcoSubmission.check_cache() if __name__ == "__main__": run()