-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathloop-unprocessed-files
More file actions
executable file
·68 lines (54 loc) · 1.81 KB
/
loop-unprocessed-files
File metadata and controls
executable file
·68 lines (54 loc) · 1.81 KB
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
#!/bin/sh
PREFIX="Loop unprocessed files"
API=${API:-http://validator-api/api/v1}
DWB_DATASET_MAXDAYSOBSOLETE=${DWB_DATASET_MAXDAYSOBSOLETE:-30}
./update-data.sh
# loop forever
while :
do
# request a file to be processed
# Refresh a report after DWB_DATASET_MAXDAYSOBSOLETE days (JSON is the last bit updated in the processing
# so we check for this to select incomplete or obsolete data)
TDone=`date -d "$DWB_DATASET_MAXDAYSOBSOLETE days ago" -u --iso-8601=seconds`
# Restart processing if the last start was more than 2 hour ago
TProc=`date -d "2 hours ago" -u --iso-8601=seconds`
QUERY=`cat <<EOT
{
"limit": 1,
"where": {
"and": [
{"or": [
{"json-updated": {"exists": false}},
{"json-updated": {"lt": "$TDone"}},
{"svrl-updated": {"exists": false}},
{"svrl-updated": {"lt": "$TDone"}}
]},
{"or":[
{"processing": {"exists": false}},
{"processing": {"lt": "$TProc"}}
]}
]
}
}
EOT`
# Get (-G) a dataset with the query
DATASET=`curl -sS --header 'Accept: application/xml' \
-G --data-urlencode "filter=$QUERY" \
"$API/iati-datasets"`
MD5=`echo $DATASET | xmllint --xpath '//md5/text()' -` 2> "/dev/null"
DSID=`echo $DATASET | xmllint --xpath '//id/text()' -` 2> "/dev/null"
if [ -z $MD5 ]; then
echo "$PREFIX: Nothing found to process, waiting"
sleep 1m
else
echo "$PREFIX: Found $MD5 -- start processing"
NOW=`date --iso-8601=seconds`
APIDATA="{\"processing\": \"$NOW\"}"
echo "$PREFIX: update iati-datasets $MD5 to indicate processing"
curl -sS -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' \
-d "$APIDATA" \
"$API/iati-datasets/update?where=%7B%22id%22%3A%22$DSID%22%7D"
echo "$PREFIX: process $MD5"
./webhook-scripts/inhouse.sh $MD5
fi
done