-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_duplicated.py
70 lines (55 loc) · 1.71 KB
/
move_duplicated.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
import pathlib
import glob
import json
import shutil
def load_file(file_path):
with open(file_path, "r") as fp:
json_data = json.load(fp)
return json_data
stage_weight = {
"INGEST": 0,
"DEPOSIT": 1,
"FINALIZE": 2,
"FINISHED": 3,
}
state_weight = {
"INITIALED": 0,
"RUNNING": 4,
"PAUSED": 1,
"SUCCEED": 5,
"FAILED": 3,
"CANCELED": 2,
}
def job_sort_key(job):
try:
stage = stage_weight[job["stage"]]
state = state_weight[job["state"]]
id = int(job["id"])
return stage * 1024 ** 4 + state * 1024 ** 2 - id
except AttributeError as e:
print(f'{job["id"]} {job["stage"]} {job["state"]}')
def main(root_path):
groupped_jobs = {}
files = glob.glob(str(pathlib.Path(root_path, "jobs", "*.json")), recursive=False)
for file_path in files:
job = load_file(file_path)
subfolder = job["injectionPath"]
if subfolder not in groupped_jobs:
groupped_jobs[subfolder] = []
groupped_jobs[subfolder].append(job)
for subfolder in groupped_jobs:
job_set = groupped_jobs[subfolder]
if len(job_set) <= 1:
continue
job_set = sorted(job_set, key=job_sort_key, reverse=True)
# print(job_set)
for job in job_set[1:]:
job_file_name = f"{job['id']}.json"
print(f'{job_file_name} {job["id"]} {job["stage"]} {job["state"]}')
shutil.move(
str(pathlib.Path(root_path, "jobs", job_file_name)),
str(pathlib.Path(root_path, "jobs-backup", job_file_name))
)
print('')
if __name__ == '__main__':
main(root_path="/exlibris/dps/nlnz_tools/dashboard/running_data")