aboutsummaryrefslogtreecommitdiffstats
path: root/python/citco_submission.py
blob: 91ac5ed20213ce4a36b7af79e98485fa8f340807 (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
41
42
43
44
45
46
47
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()