gate-resource icon indicating copy to clipboard operation
gate-resource copied to clipboard

Consider adding a TTL to autoclose gates

Open JohannesRudolph opened this issue 7 years ago • 1 comments

Our CI pipeline builds feature branches using autoclose gates. It is expected that builds on feature branches fail from time to time and may be corrected by developers. This leaves autoclose gates open and "stranded".

When processing autoclose items, the gate resource should probably perform a cleanup of gates after a configurable TTL. Thinking of it, there might be value to having a TTL for gates in general (i.e. reduced git checkout size and less load on the filesystem). This might be best delegated to a "sidecar" task that runs on the gate-repo

JohannesRudolph avatar Oct 20 '18 19:10 JohannesRudolph

I've experimented with a script like this to clean up gate files older than 7 days

#!/bin/bash

set -o errexit
set -o errtrace
set -o pipefail
set -o nounset

function cleanup()
{
  stamp=$(date +%s)
  day=$((60*60*24))
  old=$(($stamp - 7*$day))

  echo "cleaning any file commited older than $old"
  
  while read FILE; do
    
    modified=$(git log --pretty="%ad" --date=unix -1 -- "$FILE")
    if [ $modified -lt $old ]; then
      echo "$FILE $modified is old, cleaning"
      rm "$FILE"
    else
      echo "$FILE $modified is not old"
    fi;

  done < <( git ls-files )
}

cleanup

When commiting to the gate repository, use something like git commit -am "[ci skip] cleanup old gates" so that the commit is not picked up accidentally as a valid gate-modifying commit. Otherwise you'll see errors like could not determine passed file in version ... in your gate resources.

JohannesRudolph avatar Apr 15 '20 08:04 JohannesRudolph