aboutsummaryrefslogtreecommitdiffstats
path: root/python/quantifi_upload_status.py
blob: 54011c0da455b6d9c1a2fc1442196d99530f4e18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import time
import logging
from paramiko.ssh_exception import SSHException

from report_ops.status import QuantifiRemote

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def close_and_reconnect():
    retries = 5
    for i in range(retries):
        try:
            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():
    QuantifiRemote.init_client()
    while True:
        try:
            for f in QuantifiRemote._client.list_files("/OUTGOING/Status"):
                QuantifiRemote.process(f)
        except (SSHException, OSError) as e:
            logger.info(e)
            close_and_reconnect()
        time.sleep(60)
        QuantifiRemote.check_cache()


if __name__ == "__main__":
    run()