feat: maintain server until hour
This commit is contained in:
@@ -10,6 +10,7 @@ set -eu
|
||||
|
||||
gcr_state_init
|
||||
calls="$GCR_STATE_DIR/calls"
|
||||
gcr_now_epoch() { printf '1800'; }
|
||||
|
||||
gcr_vm_public_ip() {
|
||||
printf '192.0.2.%s' "$1"
|
||||
@@ -23,7 +24,13 @@ gcr_vm_destroy() {
|
||||
printf 'destroy vm=%s\n' "$1" >> "$calls"
|
||||
}
|
||||
|
||||
record_success='{"job_id":"201","run_attempt":"1","repo":"hinterland/hearth","label":"gross-nix-x86-perf","created_at":"1","ttl_min":480,"vm_id":51,"vm_name":"gcr-201-1","bootstrapped":true,"status":"vm_active"}'
|
||||
gcr_vm_runner_service() {
|
||||
printf 'runner %s vm=%s\n' "$2" "$1" >> "$calls"
|
||||
}
|
||||
|
||||
gcr_gitea_runner_disabled() { :; }
|
||||
|
||||
record_success='{"job_id":"201","run_attempt":"1","repo":"hinterland/hearth","label":"gross-nix-x86-perf","created_at":"0","ttl_min":480,"vm_id":51,"vm_name":"gcr-201-1","bootstrapped":true,"status":"vm_active"}'
|
||||
record_failure='{"job_id":"202","run_attempt":"1","repo":"hinterland/hearth","label":"gross-nix-x86-perf","created_at":"1","ttl_min":480,"vm_id":52,"vm_name":"gcr-202-1","bootstrapped":true,"status":"vm_active"}'
|
||||
|
||||
gcr_record_put 201 1 "$record_success"
|
||||
@@ -31,7 +38,6 @@ gcr_record_put 202 1 "$record_failure"
|
||||
gcr_deallocate 201 1 completed:success
|
||||
gcr_deallocate 202 1 completed:failure
|
||||
|
||||
grep -q 'destroy vm=51' "$calls"
|
||||
grep -q 'destroy vm=52' "$calls"
|
||||
grep -q 'diag vm=52 ip=192.0.2.52 job=202 reason=completed:failure' "$calls"
|
||||
if grep -q 'diag vm=51' "$calls"; then
|
||||
@@ -39,7 +45,15 @@ if grep -q 'diag vm=51' "$calls"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
test ! -e "$(gcr_record_path 201 1)"
|
||||
if grep -q 'destroy vm=51' "$calls"; then
|
||||
printf 'successful webhook VM should remain idle until billing boundary\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
jq -e 'select(.status == "idle_vm" and .idle_expires_at == 3600)' \
|
||||
"$(gcr_record_path 201 1)" >/dev/null
|
||||
idle_once="$(gcr_record_get 201 1)"
|
||||
gcr_deallocate 201 1 completed:success
|
||||
test "$(gcr_record_get 201 1)" = "$idle_once"
|
||||
test ! -e "$(gcr_record_path 202 1)"
|
||||
|
||||
calls_ip_fail="$GCR_STATE_DIR/calls-ip-fail"
|
||||
|
||||
Reference in New Issue
Block a user