-
Notifications
You must be signed in to change notification settings - Fork 1
/
alohaFindCompletedJobs
executable file
·99 lines (83 loc) · 2.49 KB
/
alohaFindCompletedJobs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
CmdName=$(basename "$0")
Syntax="${CmdName} [-n][-v]{-c CompletedJobsJsonFile}{-g GearName}{-b BaselineSessionId}{-f FollowupSessionId}{-j BaselineJobsJsonFile}"
function sys {
[ -n "${opt_n}${opt_v}" ] && echo "$@" 1>&2
[ -n "$opt_n" ] || "$@"
}
while getopts b:c:f:g:j:nv arg
do
case "$arg" in
b|c|f|g|j|n|v)
eval "opt_${arg}='${OPTARG:=1}'"
;;
esac
done
shift $(("$OPTIND" - 1))
if [ -n "$opt_b" ]
then
BaselineSessionId="$opt_b"
else
echo "${CmdName} : Missing -b BaselineSessionId" 1>&2
echo "$Syntax" 1>&2
exit 1
fi
if [ -n "$opt_c" ]
then
CompletedJobsJsonFile="$opt_c"
else
echo "${CmdName} : Missing -c CompletedJobsJsonFile" 1>&2
echo "$Syntax" 1>&2
exit 1
fi
if [ -n "$opt_f" ]
then
FollowupSessionId="$opt_f"
else
echo "${CmdName} : Missing -f FollowupSessionId" 1>&2
echo "$Syntax" 1>&2
exit 1
fi
if [ -n "$opt_g" ]
then
GearName="$opt_g"
else
echo "${CmdName} : Missing -g GearName" 1>&2
echo "$Syntax" 1>&2
exit 1
fi
if [ -n "$opt_j" ]
then
BaselineJobsJsonFile="$opt_j"
else
echo "${CmdName} : Missing -j BaselineJobsJsonFile" 1>&2
echo "$Syntax" 1>&2
exit 1
fi
if [ ! -e "$BaselineJobsJsonFile" ]
then
BaselineSessionLabel=$(fwget -1 "$BaselineSessionId" | jq -r '.label')
sys alohaUpdateJobsJsonFile "$BaselineSessionLabel" "$BaselineSessionId" "$BaselineJobsJsonFile"
if [ "$?" != 0 ]
then
echo "${CmdName} : Could not update BaselineJobsJsonFile" 1>&2
exit 2
fi
fi
jq -r 'select( (.gear_info.name == "'"$GearName"'") and (.detail.state == "complete"))' "$BaselineJobsJsonFile" > "$CompletedJobsJsonFile"
# -c to keep jq's output on one line. sort -r so the most recent one is first
JobInputFileIdsJson=$(jq -c -r '._id as $JobId | .created as $JobDateTime | { "JobDateTime": $JobDateTime, "JobId": $JobId, "FileId" : [ (.inputs[].id) ] }' "$CompletedJobsJsonFile" | sort -r)
while read l
do
JobId=$(echo "$l" | jq -r .JobId)
JobDateTime=$(echo "$l" | jq -r .JobDateTime)
FileIds=$(echo "$l" | jq -r .FileId[])
InputParentSessionIds=$(echo "$FileIds" | fwget -1 | jq -r .parents.session | sort -u)
if (echo "$InputParentSessionIds" | grep -q "$BaselineSessionId") && (echo "$InputParentSessionIds" | grep -q "$FollowupSessionId")
then
[ -n "$opt_v" ] && echo "{ \"JobDateTime\": ${JobDateTime}, \"JobId\": ${JobId}, \"InputSessionIds\": [ ${InputParentSessionIds} ] }" 1>&2
echo "$JobId"
exit 0
fi
done <<< "$JobInputFileIdsJson"
echo "No $GearName matching $BaselineSessionId and $FollowupSessionId" 1>&2