1 |
7083
|
aaronmk
|
#!/bin/bash
|
2 |
|
|
# Adds scrubbed taxondeterminations to VegBIEN
|
3 |
7085
|
aaronmk
|
# Usage: make inputs/.TNRS/public.unscrubbed_taxondetermination_view/scrub-remake [wait=1]
|
4 |
7083
|
aaronmk
|
|
5 |
7235
|
aaronmk
|
# Handle being run as a .make script
|
6 |
|
|
exec >&2
|
7 |
|
|
unset MAKEFLAGS MFLAGS
|
8 |
|
|
|
9 |
7083
|
aaronmk
|
selfDir="$(dirname -- "$0")"
|
10 |
|
|
selfDirName="$(basename -- "$selfDir")"
|
11 |
|
|
|
12 |
7274
|
aaronmk
|
# Use tnrs.make's lockfile because can't be importing while tnrs.make is
|
13 |
|
|
# scrubbing. tnrs.make leaves tnrs in an incomplete state while running because
|
14 |
|
|
# the accepted names are parsed *after* their matched names. Using a separate
|
15 |
|
|
# lockfile would cause some accepted names to be missing.
|
16 |
|
|
waitself "tnrs/tnrs.make"
|
17 |
|
|
|
18 |
7085
|
aaronmk
|
# Config
|
19 |
|
|
let pause=2*60*60 # sec; = 2 hr
|
20 |
7154
|
aaronmk
|
let maxPause=4*60*60 # sec; =4 hr; must be >= max partition import time (1.5 hr)
|
21 |
7085
|
aaronmk
|
test "$pause" -le "$maxPause" || exit -1
|
22 |
|
|
|
23 |
7108
|
aaronmk
|
unset n # ($n would limit the # rows/iteration, rather than the total rows)
|
24 |
|
|
|
25 |
7083
|
aaronmk
|
cd "$selfDir/.." # needed by make
|
26 |
|
|
|
27 |
|
|
make () { env make --makefile=../input.Makefile "$@"; }
|
28 |
|
|
|
29 |
|
|
log_="$(make -s "$selfDirName"/log_file)"
|
30 |
|
|
exec >>"$log_" 2>&1
|
31 |
|
|
|
32 |
7084
|
aaronmk
|
rowsAdded ()
|
33 |
|
|
{
|
34 |
7236
|
aaronmk
|
test -e "$log_" || { echo "Log does not exist: $log_" >&2; exit;}
|
35 |
7237
|
aaronmk
|
tail -100 "$log_"|grep -E '^Inserted [1-9][0-9]* new rows into database$' \
|
36 |
7084
|
aaronmk
|
>/dev/null
|
37 |
|
|
}
|
38 |
|
|
|
39 |
7085
|
aaronmk
|
let totalPause=0
|
40 |
7083
|
aaronmk
|
while true; do
|
41 |
|
|
make "$selfDirName"/import
|
42 |
|
|
|
43 |
7085
|
aaronmk
|
if ! rowsAdded; then
|
44 |
|
|
test -n "$wait" || break
|
45 |
|
|
echo "Waited $totalPause sec total"
|
46 |
|
|
let 'totalPause += pause'
|
47 |
|
|
test "$totalPause" -gt "$maxPause" && break
|
48 |
|
|
echo "Waiting $pause sec..."
|
49 |
|
|
sleep "$pause" # wait for more rows
|
50 |
|
|
continue # try again
|
51 |
|
|
fi
|
52 |
|
|
# otherwise, rows found
|
53 |
|
|
let totalPause=0
|
54 |
7083
|
aaronmk
|
done
|