Skip to content

Commit

Permalink
Merge pull request #348 from Martchus/retrigger
Browse files Browse the repository at this point in the history
Use a single API query in `openqa-advanced-retrigger-jobs`
  • Loading branch information
mergify[bot] authored Oct 14, 2024
2 parents b4ba622 + 4d7b963 commit 0f7d7e0
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions openqa-advanced-retrigger-jobs
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/bin/sh -e
#worker="${worker:-"openqaworker4"}"
#!/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
for i in $(ssh "$host" "sudo -u geekotest psql --no-align --tuples-only --command=\"select id from jobs where (${worker_string}${result} and clone_id is null and t_finished >= '$failed_since'$additional_filters);\" openqa"); do
$client_prefix openqa-cli api --host "$host" -X POST jobs/"$i"/restart
[ -n "$comment" ] && $client_prefix openqa-cli api --host "$host" -X POST jobs/"$i"/comments text="$comment"
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

0 comments on commit 0f7d7e0

Please sign in to comment.