pull time

This commit is contained in:
Amber 2021-07-28 17:17:44 +02:00
parent 23ee2bd74a
commit f40376d239
1 changed files with 22 additions and 3 deletions

View File

@ -37,10 +37,23 @@ exec {lock_deletes}>>${TMPQUEUEDELETES}
#acquire lock queue file descriptor
exec {lock_queue}>>${TMPQUEUEFILE}
min() {
if [ $1 -gt $2 ]; then
echo $2
else
echo $1
fi
}
synccycle() {
lastsynctime="$(date -u +%s.%N)"
### max waiting time for pull (seconds)
maxpulllimit=60
### initial max waiting time for pull (seconds) used as unit
pulllimitunit=60
pulliteration=1
let "maxpulllimit = $pulllimitunit * $pulliteration"
echo "inital maxpulllimit: $maxpulllimit"
### max waiting time for pull (seconds) 10 min
thresholdpulllimit=600
while :
do
if [ -f "$TMPQUEUEFILE" ] || [ -f "$TMPQUEUEDELETES" ]; then
@ -76,19 +89,25 @@ synccycle() {
cat ${tmpfile} > ${TMPQUEUEFILE}
rm -f ${tmpfile}
flock -u $lock_queue
lastsynctime="$(date -u +%s.%N)"
#lastsynctime="$(date -u +%s.%N)"
nqueue=$(wc -l < ${TMPQUEUEFILE})
done
fi
fi
now="$(date -u +%s.%N)"
elapsed="$(bc <<<"$now-$lastsynctime")"
echo "maxpulllimit: $maxpulllimit"
## if elapsed is greater than maxpulllimit sync from remote with delete option
if [ 1 -eq $(echo "$elapsed>$maxpulllimit" | bc) ]; then
echo 'maxpulllimit reached: sync from remote with --delete option'
sync $LOCALPATH_HASH $REMOTEPATH $LOCALPATH '--delete'
lastsynctime="$(date -u +%s.%N)"
## increment the pull iteration
let pulliteration++
let "limit = $pulliteration * $pulliteration * $pulllimitunit"
maxpulllimit=$(min $limit $thresholdpulllimit)
fi
sleep 10
done
}