mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

commit fa595281e5de8d1842a892fd3deb9b7a4391e927
parent 2c08c332c85f2a412ba0aa49db549e617277f5e1
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 27 Sep 2016 00:00:44 +0200

log errors

Diffstat:
svn-poll | 24+++++++++++++++++++++---
svn-poll-init | 12++++++++++--
2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/svn-poll b/svn-poll @@ -7,13 +7,16 @@ # TODO: include svn diff +# after this many failures, complain +MAX_ERRORS="100" + URL="$1" USER="$2" BASE=$(base64 <<<"$URL") DIR="$HOME/temp/svn-poll/$BASE" FILE="$DIR/rev" MUTEFILE="$DIR/muted" -RETRIES="$DIR/retries" +ERRORS="$DIR/errors" mkdir -p "$DIR" @@ -23,8 +26,21 @@ LATEST="$(svn info "$URL" | grep Revision | cut -d' ' -f2)" re='^[0-9]+$' if ! [[ $LATEST =~ $re ]] ; then # importantly, don't save $LATEST then - echo "problem when fetching latest revision: got $LATEST" >&2 - exit 1 + # log the error + echo "problem when fetching latest revision: got $LATEST" >>"$ERRORS" + # now, should we whine... + NERRORS=$(cat "$ERRORS" | wc -l) + if [ $NERRORS -gt $MAX_ERRORS ] + then + # whine + echo "errors encountered in the last $MAX_ERRORS attempts:" >&2 + cat "$ERRORS" >&2 + # reset the errors + echo "" > $ERRORS + exit 1 + fi + # if we are here, we decided not to whine + exit 0 fi if [[ -f "$FILE" ]] @@ -68,4 +84,6 @@ done # now that it's been processed, save it echo "$LATEST" > "$FILE" +# and reset the retries counter +echo "" > "$RETRIES" diff --git a/svn-poll-init b/svn-poll-init @@ -7,12 +7,20 @@ URL="$1" BASE=$(base64 <<<"$URL") DIR="$HOME/temp/svn-poll/$BASE" FILE="$DIR/rev" -RETRIES="$DIR/retries" +ERRORS="$DIR/errors" mkdir -p "$DIR" LATEST="$(svn info "$URL" | grep Revision | cut -d' ' -f2)" +# http://stackoverflow.com/a/806923/414272 +re='^[0-9]+$' +if ! [[ $LATEST =~ $re ]] ; then + # bail out + echo "problem when fetching latest revision: got $LATEST" >&2 + exit 1 +fi + echo "$LATEST" > "$FILE" -echo 0 > "$RETRIES" +echo "" > "$ERRORS"