Fixed ExecTasks parallelExec runs

This commit is contained in:
deajan 2018-01-03 15:11:16 +01:00
parent 276fc8c082
commit ebf8b106d5
1 changed files with 29 additions and 23 deletions

View File

@ -3,7 +3,7 @@
#### OFUNCTIONS MINI SUBSET #### #### OFUNCTIONS MINI SUBSET ####
_OFUNCTIONS_VERSION=2.2.0-dev _OFUNCTIONS_VERSION=2.2.0-dev
_OFUNCTIONS_BUILD=2018010201 _OFUNCTIONS_BUILD=2018010302
#### _OFUNCTIONS_BOOTSTRAP SUBSET #### #### _OFUNCTIONS_BOOTSTRAP SUBSET ####
_OFUNCTIONS_BOOTSTRAP=true _OFUNCTIONS_BOOTSTRAP=true
#### _OFUNCTIONS_BOOTSTRAP SUBSET END #### #### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
@ -700,7 +700,11 @@ function ParallelExec {
local spinner="${9:-false}" local spinner="${9:-false}"
local noErrorLog="${10:-false}" local noErrorLog="${10:-false}"
ExecTasks "base" 0 0 "$softMaxTime" "$hardMaxTime" "$sleepTime" "$keepLogging" "$counting" "$spinner" "$noErrorLog" false 3 "$commandsArg" "" "$numberOfProcesses" if [ $readFromFile == true ]; then
ExecTasks "base" 0 0 "$softMaxTime" "$hardMaxTime" "$sleepTime" "$keepLogging" "$counting" "$spinner" "$noErrorLog" false 6 "$commandsArg" "" "$numberOfProcesses"
else
ExecTasks "base" 0 0 "$softMaxTime" "$hardMaxTime" "$sleepTime" "$keepLogging" "$counting" "$spinner" "$noErrorLog" false 3 "$commandsArg" "" "$numberOfProcesses"
fi
} }
## Main asynchronous execution function ## Main asynchronous execution function
@ -754,6 +758,7 @@ function ExecTasks {
local counting="${8:-true}" # Count time since function has been launched (true), or since script has been launched (false) local counting="${8:-true}" # Count time since function has been launched (true), or since script has been launched (false)
local spinner="${9:-true}" # Show spinner (true), do not show anything (false) local spinner="${9:-true}" # Show spinner (true), do not show anything (false)
local noTimeErrorLog="${10:-false}" # Log errors when reaching soft / hard max time (false), do not log errors on those triggers (true) local noTimeErrorLog="${10:-false}" # Log errors when reaching soft / hard max time (false), do not log errors on those triggers (true)
#TODO not implemented
local noErrorLogAtAll="${11:-false}" # Do not log errros at all (false) local noErrorLogAtAll="${11:-false}" # Do not log errros at all (false)
local execTasksMode="${12:-1}" # In which mode the function should work, see above local execTasksMode="${12:-1}" # In which mode the function should work, see above
local mainInput="${13}" # Contains list of pids / commands or filepath to list of pids / commands local mainInput="${13}" # Contains list of pids / commands or filepath to list of pids / commands
@ -782,7 +787,7 @@ function ExecTasks {
fi fi
# ParallelExec specific variables # ParallelExec specific variables
local auxCount # Number of conditional commands local auxItemCount=0 # Number of conditional commands
local commandsArray=() # Array containing commands local commandsArray=() # Array containing commands
local commandsConditionArray=() # Array containing conditional commands local commandsConditionArray=() # Array containing conditional commands
local currentCommand # Variable containing currently processed command local currentCommand # Variable containing currently processed command
@ -793,7 +798,7 @@ function ExecTasks {
# Common variables # Common variables
local pid # Current pid working on local pid # Current pid working on
local pidState # State of the process local pidState # State of the process
local mainItemCount # number of given items (pids or commands) local mainItemCount=0 # number of given items (pids or commands)
local readFromFile # Should we read pids / commands from a file (true) local readFromFile # Should we read pids / commands from a file (true)
local counter=0 local counter=0
local log_ttime=0 # local time instance for comparaison local log_ttime=0 # local time instance for comparaison
@ -837,7 +842,6 @@ function ExecTasks {
mainItemCount=$(wc -l < "$mainInput") mainItemCount=$(wc -l < "$mainInput")
readFromFile=true readFromFile=true
else else
mainItemCount=0
Logger "Cannot read file [$mainInput]." "WARN" Logger "Cannot read file [$mainInput]." "WARN"
fi fi
functionMode=WaitForTaskCompletion functionMode=WaitForTaskCompletion
@ -877,7 +881,6 @@ function ExecTasks {
mainItemCount=$(wc -l < "$mainInput") mainItemCount=$(wc -l < "$mainInput")
readFromFile=true readFromFile=true
else else
mainItemCount=0
Logger "Cannot read file [$mainInput]." "WARN" Logger "Cannot read file [$mainInput]." "WARN"
fi fi
functionMode=ParallelExec functionMode=ParallelExec
@ -888,13 +891,11 @@ function ExecTasks {
mainItemCount=$(wc -l < "$mainInput") mainItemCount=$(wc -l < "$mainInput")
readFromFile=true readFromFile=true
else else
mainItemCount=0
Logger "Cannot read file [$mainInput]." "WARN" Logger "Cannot read file [$mainInput]." "WARN"
fi fi
if [ -f "$auxInput" ]; then if [ -f "$auxInput" ]; then
auxCount=$(wc -l < "$auxInput") auxItemCount=$(wc -l < "$auxInput")
else else
auxCount=0
Logger "Cannot read file [$auxInput]." "WARN" Logger "Cannot read file [$auxInput]." "WARN"
fi fi
postPoneIfConditionFails=false postPoneIfConditionFails=false
@ -906,13 +907,11 @@ function ExecTasks {
mainItemCount=$(wc -l < "$mainInput") mainItemCount=$(wc -l < "$mainInput")
readFromFile=true readFromFile=true
else else
mainItemCount=0
Logger "Cannot read file [$mainInput]." "WARN" Logger "Cannot read file [$mainInput]." "WARN"
fi fi
if [ -f "$auxInput" ]; then if [ -f "$auxInput" ]; then
auxCount=$(wc -l < "$auxInput") auxItemCount=$(wc -l < "$auxInput")
else else
auxCount=0
Logger "Cannot read file [$auxInput]." "WARN" Logger "Cannot read file [$auxInput]." "WARN"
fi fi
postPoneIfConditionFails=true postPoneIfConditionFails=true
@ -989,18 +988,22 @@ function ExecTasks {
while [ $counter -lt "$mainItemCount" ] && [ ${#pidsArray[@]} -lt $numberOfProcesses ]; do while [ $counter -lt "$mainItemCount" ] && [ ${#pidsArray[@]} -lt $numberOfProcesses ]; do
if [ $readFromFile == true ]; then if [ $readFromFile == true ]; then
currentCommand=$(awk 'NR == num_line {print; exit}' num_line=$((counter+1)) "$mainInput") currentCommand=$(awk 'NR == num_line {print; exit}' num_line=$((counter+1)) "$mainInput")
currentCommandCondition=$(awk 'NR == num_line {print; exit}' num_line=$((counter+1)) "$auxInput") if [ $auxItemCount -ne 0 ]; then
currentCommandCondition=$(awk 'NR == num_line {print; exit}' num_line=$((counter+1)) "$auxInput")
fi
else else
currentCommand="${commandArray[$counter]}" currentCommand="${commandsArray[$counter]}"
currentCommandCondition="${commandConditionArray[$counter]}" if [ $auxItemCount -ne 0 ]; then
currentCommandCondition="${commandsConditionArray[$counter]}"
fi
fi fi
executeCommand=false executeCommand=false
if [ $auxCount -ne 0 ]; then if [ $auxItemCount -ne 0 ]; then
Logger "Checking condition [$currentCommandCondition] for command [$currentCommand]." "DEBUG" Logger "Checking condition [$currentCommandCondition] for command [$currentCommand]." "DEBUG"
eval "$currentCommandCondition" & eval "$currentCommandCondition" &
ExecTasks "subConditionCheck" 0 0 1800 3600 1 $KEEP_LOGGING true true true true 1 $! ExecTasks "subConditionCheck" 0 0 1800 3600 1 $KEEP_LOGGING true true true true 1 $!
if [ $? -ne 0 ]; then retval=$?
if [ $retval -ne 0 ]; then
if [ $postPoneIfConditionFails == true ]; then if [ $postPoneIfConditionFails == true ]; then
Logger "Condition not met for command [$currentCommand]. Postponing command." "NOTICE" Logger "Condition not met for command [$currentCommand]. Postponing command." "NOTICE"
if [ $readFromFile == true ]; then if [ $readFromFile == true ]; then
@ -1008,7 +1011,7 @@ function ExecTasks {
echo "$currentCommand" >> "$mainInput" echo "$currentCommand" >> "$mainInput"
echo "$currentCommandCondition" >> "$auxInput" echo "$currentCommandCondition" >> "$auxInput"
else else
commansdArray+=($currentCommand) commandsArray+=($currentCommand)
commandsConditionArray+=($currentCommandCondition) commandsConditionArray+=($currentCommandCondition)
fi fi
mainItemCount=$((mainItemCount+1)) mainItemCount=$((mainItemCount+1))
@ -1033,7 +1036,9 @@ function ExecTasks {
commandsArrayPid[$pid]="$currentCommand" commandsArrayPid[$pid]="$currentCommand"
#TODO not implemented #TODO not implemented
pidsTimeArray[$pid]=$((SECONDS - seconds_begin)) pidsTimeArray[$pid]=$((SECONDS - seconds_begin))
fi else
Logger "Skipping command [$currentCommand]." "DEBUG"
fi
counter=$((counter+1)) counter=$((counter+1))
done done
fi fi
@ -1085,9 +1090,10 @@ function ExecTasks {
# Return exit code if only one process was monitored, else return number of errors # Return exit code if only one process was monitored, else return number of errors
# As we cannot return multiple values, a global variable WAIT_FOR_TASK_COMPLETION contains all pids with their return value # As we cannot return multiple values, a global variable WAIT_FOR_TASK_COMPLETION contains all pids with their return value
if [ $noErrorLogAtAll == true ]; then #WIP: return code has nothing to do with logging
return 0 #if [ $noErrorLogAtAll == true ]; then
fi # return 0
#fi
if [ $mainItemCount -eq 1 ]; then if [ $mainItemCount -eq 1 ]; then
return $retval return $retval