diff options
Diffstat (limited to 'python/quantifi_status.py')
| -rw-r--r-- | python/quantifi_status.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/python/quantifi_status.py b/python/quantifi_status.py new file mode 100644 index 00000000..04376b2c --- /dev/null +++ b/python/quantifi_status.py @@ -0,0 +1,50 @@ +from stat import S_ISREG +import time +from contextlib import contextmanager +from report_ops.status import QuantifiRemote +from paramiko.ssh_exception import SSHException +import logging +from psycopg.errors import UniqueViolation +from contextlib import contextmanager + + +@contextmanager +def retry_on_exception_sftp(): + yield + + +def close_and_reconnect(): + retries = 5 + for i in range(retries): + try: + with retry_on_exception_sftp(): + QuantifiRemote._client.client.close() + QuantifiRemote.init_client() + except (SSHException, OSError) as e: + if i == retries - 1: + raise e + else: + time.sleep(60 * i) + else: + return + + +def run(): + try: + for f in QuantifiRemote._client.list_files("/OUTGOING/Status"): + item = QuantifiRemote.process(f) + item.stage() + try: + item.commit() + except UniqueViolation: + item._conn.rollback() + finally: + item._insert_queue.clear() + except (SSHException, OSError): + close_and_reconnect() + time.sleep(60) + QuantifiRemote.check_cache() + + +if __name__ == "__main__": + run() |
