Skip to content

Commit

Permalink
Add include-on-hold option to treat on-hold workflows as running in q…
Browse files Browse the repository at this point in the history
…ueue
  • Loading branch information
tkoft committed Oct 18, 2023
1 parent 0022cc4 commit 3c9c72b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/commands/block_execution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ parameters:
Due to concurrency issues, how many times should we requery the pipeline list to ensure previous jobs are "pending",
but not yet active. This number indicates the threshold for API returning no previous pending pipelines.
Default is one confirmation, increase if you see issues.
include-on-hold:
type: boolean
default: false
description: Consider on-hold workflows waiting for approval as running and include them in the queue.

steps:
- run:
Expand All @@ -35,4 +39,5 @@ steps:
CONFIG_DONT_QUIT: "<< parameters.dont-quit >>"
CONFIG_ONLY_ON_BRANCH: "<< parameters.only-on-branch >>"
CONFIG_CONFIDENCE: "<< parameters.confidence >>"
CONFIG_INCLUDE_ON_HOLD: " << parameters.include-on-hold >>"
command: <<include(scripts/queue.sh)>>
5 changes: 5 additions & 0 deletions src/jobs/queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ parameters:
Due to concurrency issues, how many times should we requery the pipeline list to ensure previous jobs are "pending",
but not yet active. This number indicates the threshold for API returning no previous pending pipelines.
Default is one confirmation, increase if you see issues.
include-on-hold:
type: boolean
default: false
description: Consider on-hold workflows waiting for approval as running and include them in the queue.

steps:
- block_execution:
Expand All @@ -37,3 +41,4 @@ steps:
dont-quit: <<parameters.dont-quit>>
only-on-branch: <<parameters.only-on-branch>>
confidence: <<parameters.confidence>>
include-on-hold: <<parameters.include-on-hold>>
7 changes: 6 additions & 1 deletion src/scripts/queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ fetch_pipeline_workflows(){
created_at=$(jq -r '.items[] | .created_at' "${pipeline_detail}")
debug "Pipeline's workflow was created at: ${created_at}"
done
jq -s '[.[].items[] | select((.status == "running") or (.status == "created"))]' ${tmp}/pipeline-*.json > ${workflows_file}
if [ "${CONFIG_INCLUDE_ON_HOLD}" == "1" ]; then
active_statuses='["running","created","on_hold"]'
else
active_statuses='["running","created"]'
fi
jq -s '[.[].items[] | select([.status] | inside('${active_statuses}'))]' ${tmp}/pipeline-*.json > ${workflows_file}
}

# parse workflows to fetch parmeters about this current running workflow
Expand Down

0 comments on commit 3c9c72b

Please sign in to comment.