-
Notifications
You must be signed in to change notification settings - Fork 22
/
openqa-advanced-retrigger-jobs
executable file
·30 lines (28 loc) · 1.26 KB
/
openqa-advanced-retrigger-jobs
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
#!/bin/bash -e
host="${host:-"openqa.opensuse.org"}"
failed_since="${failed_since:-"$(date -I)"}"
instance_string="${INSTANCE+" and instance='$INSTANCE'"}"
worker_string="${WORKER+"assigned_worker_id in (select id from workers where (host='$WORKER'$instance_string)) and "}"
result="${result:-"result='incomplete'"}"
additional_filters="${additional_filters+" and $additional_filters"}"
comment="${comment:-""}"
max_jobs_per_request=25
dry_run="${dry_run:-"0"}"
[ "$dry_run" = "1" ] && client_prefix="echo"
sql_command="select id from jobs where (${worker_string}${result} and clone_id is null and t_finished >= '$failed_since'$additional_filters);"
# shellcheck disable=SC2029
job_ids=${JOB_IDS:-$(ssh "$host" "sudo -u geekotest psql --no-align --tuples-only --command=\"$sql_command\" openqa")}
query_params=()
[[ $cli_protocol ]] && host=$cli_protocol://$host
[[ $cli_port ]] && host+=:$cli_port
restart-jobs() {
[[ ${#query_params[@]} -lt 1 ]] && return
[[ $comment ]] && query_params+=("comment=$comment")
$client_prefix openqa-cli api --host "$host" -X POST jobs/restart "${query_params[@]}"
query_params=()
}
for job_id in $job_ids; do
query_params+=("jobs=$job_id")
[[ ${#query_params[@]} -ge "$max_jobs_per_request" ]] && restart-jobs
done
restart-jobs