Align reviewer runtime and Telegram notifications
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
DEFAULT_POLL_SECONDS=10
|
||||
DEFAULT_HEARTBEAT_SECONDS=60
|
||||
DEFAULT_SOFT_TIMEOUT_SECONDS=600
|
||||
DEFAULT_STALL_WARNING_SECONDS=300
|
||||
DEFAULT_HARD_TIMEOUT_SECONDS=1800
|
||||
@@ -12,7 +13,9 @@ COMMAND_FILE=""
|
||||
STDOUT_FILE=""
|
||||
STDERR_FILE=""
|
||||
STATUS_FILE=""
|
||||
SUCCESS_FILES=()
|
||||
POLL_SECONDS=$DEFAULT_POLL_SECONDS
|
||||
HEARTBEAT_SECONDS=$DEFAULT_HEARTBEAT_SECONDS
|
||||
SOFT_TIMEOUT_SECONDS=$DEFAULT_SOFT_TIMEOUT_SECONDS
|
||||
STALL_WARNING_SECONDS=$DEFAULT_STALL_WARNING_SECONDS
|
||||
HARD_TIMEOUT_SECONDS=$DEFAULT_HARD_TIMEOUT_SECONDS
|
||||
@@ -29,7 +32,9 @@ Usage:
|
||||
--stdout-file <path> \
|
||||
--stderr-file <path> \
|
||||
--status-file <path> \
|
||||
[--success-file <path>] \
|
||||
[--poll-seconds <int>] \
|
||||
[--heartbeat-seconds <int>] \
|
||||
[--soft-timeout-seconds <int>] \
|
||||
[--stall-warning-seconds <int>] \
|
||||
[--hard-timeout-seconds <int>]
|
||||
@@ -55,6 +60,25 @@ escape_note() {
|
||||
printf '%s' "$note"
|
||||
}
|
||||
|
||||
join_success_files() {
|
||||
if [[ ${#SUCCESS_FILES[@]} -eq 0 ]]; then
|
||||
printf ''
|
||||
return 0
|
||||
fi
|
||||
|
||||
local joined=""
|
||||
local path
|
||||
|
||||
for path in "${SUCCESS_FILES[@]}"; do
|
||||
if [[ -n "$joined" ]]; then
|
||||
joined+=", "
|
||||
fi
|
||||
joined+="$path"
|
||||
done
|
||||
|
||||
printf '%s' "$joined"
|
||||
}
|
||||
|
||||
iso_timestamp() {
|
||||
date -u +"%Y-%m-%dT%H:%M:%SZ"
|
||||
}
|
||||
@@ -147,10 +171,18 @@ parse_args() {
|
||||
STATUS_FILE=${2:-}
|
||||
shift 2
|
||||
;;
|
||||
--success-file)
|
||||
SUCCESS_FILES+=("${2:-}")
|
||||
shift 2
|
||||
;;
|
||||
--poll-seconds)
|
||||
POLL_SECONDS=${2:-}
|
||||
shift 2
|
||||
;;
|
||||
--heartbeat-seconds)
|
||||
HEARTBEAT_SECONDS=${2:-}
|
||||
shift 2
|
||||
;;
|
||||
--soft-timeout-seconds)
|
||||
SOFT_TIMEOUT_SECONDS=${2:-}
|
||||
shift 2
|
||||
@@ -179,11 +211,13 @@ parse_args() {
|
||||
[[ -n "$STATUS_FILE" ]] || fail_usage "--status-file is required"
|
||||
|
||||
require_integer "poll-seconds" "$POLL_SECONDS"
|
||||
require_integer "heartbeat-seconds" "$HEARTBEAT_SECONDS"
|
||||
require_integer "soft-timeout-seconds" "$SOFT_TIMEOUT_SECONDS"
|
||||
require_integer "stall-warning-seconds" "$STALL_WARNING_SECONDS"
|
||||
require_integer "hard-timeout-seconds" "$HARD_TIMEOUT_SECONDS"
|
||||
|
||||
[[ "$POLL_SECONDS" -gt 0 ]] || fail_usage "poll-seconds must be > 0"
|
||||
[[ "$HEARTBEAT_SECONDS" -gt 0 ]] || fail_usage "heartbeat-seconds must be > 0"
|
||||
[[ "$SOFT_TIMEOUT_SECONDS" -gt 0 ]] || fail_usage "soft-timeout-seconds must be > 0"
|
||||
[[ "$STALL_WARNING_SECONDS" -gt 0 ]] || fail_usage "stall-warning-seconds must be > 0"
|
||||
[[ "$HARD_TIMEOUT_SECONDS" -gt 0 ]] || fail_usage "hard-timeout-seconds must be > 0"
|
||||
@@ -227,8 +261,10 @@ main() {
|
||||
local last_stdout_bytes=0
|
||||
local last_stderr_bytes=0
|
||||
local last_output_change_time=$START_TIME
|
||||
local last_heartbeat_time=$START_TIME
|
||||
local soft_timeout_logged=0
|
||||
local stall_warning_logged=0
|
||||
local heartbeat_count=0
|
||||
|
||||
while kill -0 "$CHILD_PID" 2>/dev/null; do
|
||||
sleep "$POLL_SECONDS"
|
||||
@@ -239,6 +275,12 @@ main() {
|
||||
stdout_bytes=$(file_bytes "$STDOUT_FILE")
|
||||
stderr_bytes=$(file_bytes "$STDERR_FILE")
|
||||
|
||||
if [[ $((now - last_heartbeat_time)) -ge "$HEARTBEAT_SECONDS" ]]; then
|
||||
heartbeat_count=$((heartbeat_count + 1))
|
||||
append_status info in-progress "In progress ${heartbeat_count}"
|
||||
last_heartbeat_time=$now
|
||||
fi
|
||||
|
||||
if [[ "$stdout_bytes" -ne "$last_stdout_bytes" || "$stderr_bytes" -ne "$last_stderr_bytes" ]]; then
|
||||
last_output_change_time=$now
|
||||
stall_warning_logged=0
|
||||
@@ -285,6 +327,7 @@ main() {
|
||||
trap - EXIT
|
||||
|
||||
local final_stdout_bytes final_stderr_bytes
|
||||
local success_file success_bytes
|
||||
final_stdout_bytes=$(file_bytes "$STDOUT_FILE")
|
||||
final_stderr_bytes=$(file_bytes "$STDERR_FILE")
|
||||
|
||||
@@ -294,6 +337,16 @@ main() {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ${#SUCCESS_FILES[@]} -gt 0 ]]; then
|
||||
for success_file in "${SUCCESS_FILES[@]}"; do
|
||||
success_bytes=$(file_bytes "$success_file")
|
||||
if [[ "$success_bytes" -gt 0 ]]; then
|
||||
append_status info completed "reviewer completed successfully via success file $(join_success_files)"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
append_status error completed-empty-output "reviewer exited successfully with empty stdout"
|
||||
exit "$EXIT_COMPLETED_EMPTY_OUTPUT"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user