File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 22
33CONCURRENCY=${CONCURRENCY:- 5}
44
5+ # Function to wait for a background slot to be available
6+ # This function is used by run_bg to wait for a slot to be available before
7+ # running a new command in the background.
8+ # This function is can also be used to limit background functions
9+ # to a certain number of concurrent processes.
10+ # Example:
11+ # CONCURRENCY=2
12+ # function my_function {
13+ # echo "my_function: $@"
14+ # sleep 1
15+ # }
16+ # for i in {1..10}; do
17+ # wait_for_bg_slot
18+ # my_function $i &
19+ # done
20+ # wait_bg
21+ function wait_for_bg_slot {
22+ while [[ $( jobs -r | wc -l) -ge $CONCURRENCY ]]; do
23+ wait -n
24+ done
25+ }
26+
527# Function to run commands in background without exceeding $CONCURRENCY
628# processes in parallel.
729# The recommendation is to use this function at the deepest level that can be
@@ -16,11 +38,8 @@ CONCURRENCY=${CONCURRENCY:-5}
1638#
1739# For now these methods ignore errors on the calls that are made in the
1840# background.
19-
2041function run_bg {
21- while [[ $( jobs -r | wc -l) -ge $CONCURRENCY ]]; do
22- wait -n
23- done
42+ wait_for_bg_slot
2443
2544 # Cannot use the alternative suggested by SC2294 which is just "$@"&
2645 # because that doesn't accomplish what we want, as it executes the first
Original file line number Diff line number Diff line change @@ -127,7 +127,10 @@ data=$(oc get openstackdataplanenodesets --all-namespaces -o json | jq -j '
127127while read -r node address username secret namespace; do
128128 [[ -z " $node " ]] && continue
129129 if [[ " ${SOS_EDPM[0]} " == " all" || " ${SOS_EDPM[*]} " == * " ${node} " * ]]; then
130- run_bg gather_edpm_sos $node $address $username $secret $namespace
130+ # run_bg cannot be used here as that only support invoking external scripts
131+ # or executables and not functions
132+ wait_for_bg_slot
133+ gather_edpm_sos $node $address $username $secret $namespace &
131134 fi
132135done <<< " $data"
133136
Original file line number Diff line number Diff line change @@ -174,7 +174,10 @@ echo "Will retrieve SOS reports from nodes ${nodes//$'\n'/ }"
174174for node in $nodes ; do
175175 [[ -z " $node " ]] && continue
176176 # Gather SOS report for the node in background
177- run_bg gather_node_sos " $node "
177+ # run_bg cannot be used here as that only support invoking external scripts
178+ # or executables and not functions
179+ wait_for_bg_slot
180+ gather_node_sos " $node " &
178181done
179182
180183[[ $CALLED -eq 1 ]] && wait_bg
You can’t perform that action at this time.
0 commit comments