-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticker.sh
executable file
·71 lines (60 loc) · 2.5 KB
/
ticker.sh
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
#!/bin/bash
if [ -z "$AGAVE_TICKER_DB" ]; then
echo "You need to set \$AGAVE_TICKER_DB var.."
exit 0
fi
if [ -z "$AGAVE_TICKER_JOB_FILE" ]; then
echo "You need to set \$AGAVE_TICKER_JOB_FILE var.."
exit 0
fi
# check if db exists. Else creates database
if [ ! -s $AGAVE_TICKER_DB ]
then
. ./db_schema.sh
fi
# submit job and keep job id
response="$(jobs-submit -v -F $AGAVE_TICKER_JOB_FILE 2>&1)"
if [[ "$response" != "null" && "${response:0:1}" == "{" ]]
then
# obtain id from response
id=$(echo $response | jq 'try .id')
# store id into db
(sqlite3 $AGAVE_TICKER_DB "INSERT INTO current VALUES($id)") \
|| echo $(date +%Y-%m-%d%n%H:%M:%S) "Failure to insert id $id into CURRENT"
else
echo $(date +%Y-%m-%d%n%H:%M:%S) $response
fi
# check job status for each job in 'current'
ids=$(sqlite3 $AGAVE_TICKER_DB "SELECT * FROM current")
for id in $ids
do
status=$(jobs-status $id)
if [ "$status" == "FINISHED" ] || [ "$status" == "KILLED" ] || [ "$status" == "FAILED" ] || [ "$status" == "STOPPED" ]
then
jobsList=$(jobs-list -v $id)
executionSystem=$(echo $jobsList | jq '.executionSystem')
owner=$(echo $jobsList | jq '.owner')
appId=$(echo $jobsList | jq '.appId')
created=$(echo $jobsList | jq '.created')
submitTime=$(echo $jobsList | jq '.submitTime')
startTime=$(echo $jobsList | jq '.startTime')
endTime=$(echo $jobsList | jq '.endTime')
(
# inserts id and job information into COMPLETED
# if the data was successfully inserted into COMPLETED, the id is deleted from CURRENT. Else, an error message is displayed
(sqlite3 $AGAVE_TICKER_DB "INSERT INTO completed VALUES('$id', '$status', $executionSystem, $owner, $appId, $created, $submitTime, $startTime, $endTime)") && \
( (sqlite3 $AGAVE_TICKER_DB "DELETE FROM current WHERE id='$id'") || \
echo $(date +%Y-%m-%d%n%H:%M:%S) "Failure to delete $id from CURRENT") ) || \
(
# there are two situations in which id and job information cannot be inserted into COMPLETED:
# 1. Failure with db connection
# 2. id is in COMPLETED, but could not be deleted from CURRENT in a previous execution
ids2=$(sqlite3 $AGAVE_TICKER_DB "select current.id from current, completed where current.id = completed.id")
if grep $id <<< $ids2
# if id is in both CURRENT and COMPLETED, then id is deleted from CURRENT. Else, an error message is desplayed.
then (sqlite3 $AGAVE_TICKER_DB "DELETE FROM current WHERE id='$id'")
else echo $(date +%Y-%m-%d%n%H:%M:%S) "Failure to insert $id into COMPLETED"
fi
)
fi
done