File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 3 files changed +28
-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=5
12+ # for i in {1..10}; do
13+ # wait_for_bg_slot
14+ # my_funtion &
15+ # done
16+ # wait_bg
17+
18+ function wait_for_bg_slot{
19+ while [[ $( jobs -r | wc -l) -ge $CONCURRENCY ]]; do
20+ wait -n
21+ done
22+ }
23+
524# Function to run commands in background without exceeding $CONCURRENCY
625# processes in parallel.
726# The recommendation is to use this function at the deepest level that can be
@@ -16,11 +35,8 @@ CONCURRENCY=${CONCURRENCY:-5}
1635#
1736# For now these methods ignore errors on the calls that are made in the
1837# background.
19-
2038function run_bg {
21- while [[ $( jobs -r | wc -l) -ge $CONCURRENCY ]]; do
22- wait -n
23- done
39+ wait_for_bg_slot
2440
2541 # Cannot use the alternative suggested by SC2294 which is just "$@"&
2642 # 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