blob: 629d06263a744837d6a87ed0cbcae5dec51ed570 (
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
48
|
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__)
fund_sftp = {"ISOSEL": ("citco", "/outgoing/notifications")}
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:
for fund, (creds, folder) in fund_sftp.items():
CitcoSubmission.init_client(creds, folder=folder)
try:
for f in CitcoSubmission._client.client.listdir_iter(folder):
if S_ISREG(f.st_mode):
try:
CitcoSubmission.process(f.filename)
except ValueError as e:
logger.info(f"{fund}: {e}")
except (SSHException, OSError) as e:
logger.info(e)
close_and_reconnect(creds, folder)
time.sleep(60)
CitcoSubmission.check_cache()
if __name__ == "__main__":
run()
|