-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathcache_log
More file actions
executable file
·48 lines (43 loc) · 1016 Bytes
/
cache_log
File metadata and controls
executable file
·48 lines (43 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# Runs the given command.
# If a redis cache is available, redirect input into a cache log.
# If DUP=1 then we duplicate input also to stdout.
NO_CD=1 source $(git rev-parse --show-toplevel)/ci3/source
source $ci3/source_redis
name=$1
key=${2:-$(uuid)}
outfile=/tmp/$key
dup=${DUP:-0}
trap 'rm -f $outfile' EXIT
touch $outfile
function publish_log {
cat $outfile | redis_setexz $key $CI_REDIS_EXPIRE
}
function live_publish_log {
while [ -f $outfile ]; do
if [ $(( $(date +%s) - $(stat -c %Y "$outfile") )) -le 5 ]; then
publish_log
fi
sleep 5
done
}
if [ "$CI_REDIS_AVAILABLE" -eq 1 ]; then
log_str="$name log id: ${yellow}http://ci.aztec-labs.com/$key${reset}"
echo_stderr -e "$log_str"
live_publish_log &
if [ "$dup" -eq 1 ]; then
tee $outfile
if [ "$(cat $outfile | wc -l)" -ge 16 ]; then
echo_stderr -e "$log_str"
fi
else
cat >$outfile
fi
publish_log
else
if [ "$dup" -eq 1 ]; then
cat
else
cat >/dev/null
fi
fi