-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive_queue.py
74 lines (61 loc) · 2.64 KB
/
archive_queue.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import logging
import os
import time
from time import localtime, strftime
import api_DIVA as api
import config
config = config.get_config()
script_root = config["paths"]["script_root"]
mac_root_folders = config["paths"]["mac_root_path"]
drop_folders = [
os.path.join(x, config["paths"]["drop_folder"]) for x in mac_root_folders
]
archive_error_f = [os.path.join(x, config["paths"]["error"]) for x in mac_root_folders]
archive_folders = [
os.path.join(x, config["paths"]["archiving"]) for x in mac_root_folders
]
logger = logging.getLogger(__name__)
def get_archiving_list():
"""
Check all Archive folder locations and build a list of everything that is still archiving.
"""
archiving_list = []
for x in archive_folders:
archiving_list.extend([d for d in os.listdir(x) if not d.startswith(".")])
return archiving_list
def archiving_check():
"""
Check the number of active archives, pause the script if count exceeds the set limit.
"""
cycle_count = 0
startDateTime = f"{strftime('%Y-%m-%d', localtime())} 00:00:00"
while True:
try:
archive_jobs = api.get_requests(startDateTime)
if len(archive_jobs) > 15:
if cycle_count == 0:
pause_msg = f"Objects archiving: {archive_jobs}\nScript will pause while archive queue clears."
elif cycle_count % 5 == 0 and cycle_count != 30:
pause_msg = f"Archiving Queue paused for: {cycle_count*300} seconds\nCurrent active archive count: {archive_jobs}\nProcessing will resume when the active archive count drops."
elif cycle_count == 30:
pause_msg = f"Archiving Queue paused for: {cycle_count*300} seconds\nCurrent active archive count: {archive_jobs}\nSTOPPING ARCHIVE ATTEMPT, will try again later"
queue_status = 1
logger.info(pause_msg)
return queue_status
else:
pause_msg = f"Current active archive count: {archive_jobs}"
pass
cycle_count += 1
logger.info(pause_msg)
time.sleep(90)
continue
else:
queue_clear_msg = f"Archiving Queue status.\nCurrent active archive count: {archive_jobs}\nProcessing of new sets was paused for a total of {cycle_count*300} seconds.\nArchive submission will proceed."
logger.info(queue_clear_msg)
queue_status = 0
return queue_status
except Exception as e:
logger.exception(e)
break
if __name__ == "__main__":
archiving_check()