From f34a62d0ab062674ba70d60611c35e88dc60c112 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 21 Mar 2016 01:34:12 -0400 Subject: [PATCH] catalyst-auto: add a time delay option We usually run catalyst on systems via cronjob, and do so at weekly (or so) intervals. But if a failure hits a run, it will be a while before we know if changes fixed the situation. Instead, let's push the delay logic into the script itself so we can run this tool once a day. When it passes, it will take care of quitting early. When it fails, it will retry once a day until it passes. --- tools/catalyst-auto | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/catalyst-auto b/tools/catalyst-auto index a018dc94..f20aa1dc 100755 --- a/tools/catalyst-auto +++ b/tools/catalyst-auto @@ -25,6 +25,7 @@ verbose=0 keep_tmpdir=0 testing=0 preclean=0 +lastrun=0 # Set pipefail so that run_cmd returns the right value in $? set -o pipefail @@ -46,6 +47,7 @@ Options: -v|--verbose Send output of commands to console as well as log -k|--keep-tmpdir Don't remove temp dir when build finishes -t|--test Stop after mangling specs and copying files + --interval Exit if last successful run was less than ago -h|--help Show this message and quit EOH @@ -124,6 +126,10 @@ do -C|--preclean) preclean=1 ;; + --interval) + lastrun=$1 + shift + ;; -*) usage "ERROR: You have specified an invalid option: ${a}" exit 1 @@ -151,6 +157,16 @@ fi BUILD_SRCDIR_BASE=$(catalyst_var storedir) +# See if we had a recent success. +if [[ ${lastrun} -ne 0 ]]; then + last_success_file="${BUILD_SRCDIR_BASE}/.last_success" + delay=$(( lastrun * 24 * 60 * 60 )) + last_success=$(head -1 "${last_success_file}" 2>/dev/null || echo 0) + if [[ $(date +%s) -lt $(( last_success + delay )) ]]; then + exit 0 + fi +fi + TMPDIR=$(mktemp -d --tmpdir="${TMP_PATH:-/tmp}" catalyst-auto.XXXXXX) DATESTAMP=$(date +%Y%m%d) @@ -298,6 +314,11 @@ if ! run_cmd "post_build" "${TMPDIR}/log/post_build.log"; then fi if [ ${build_failure} = 0 ]; then + if [[ ${lastrun} -ne 0 ]]; then + stamp=$(date) + (date -d"${stamp}" +%s; echo "${stamp}") >"${last_success_file}" + fi + send_email "Catalyst build success" "Build process complete." if [ "${keep_tmpdir}" = 0 ]; then