Fix the bug where wait hangs forever

This commit is contained in:
Aleksandar Puharic 2024-05-17 07:25:10 +02:00
parent 2fb3374416
commit 0e70c8c099
Signed by: xZero707
GPG Key ID: 3CC53DCAA9C237BB

View File

@ -42,7 +42,7 @@ checkInstalled() {
} }
# Plugins installer # Plugins installer
function taskInstallPlugins() { taskInstallPlugins() {
export WP_PLUGINS_PATH export WP_PLUGINS_PATH
local concurrencyLimit="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}" local concurrencyLimit="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
@ -57,6 +57,8 @@ function taskInstallPlugins() {
return 0 return 0
fi fi
local jobs=()
echo "About to install defined plugins" echo "About to install defined plugins"
for pluginExpr in ${PLUGIN_LIST}; do for pluginExpr in ${PLUGIN_LIST}; do
@ -74,9 +76,11 @@ function taskInstallPlugins() {
if [ -n "${pluginVersion}" ]; then if [ -n "${pluginVersion}" ]; then
echo "Installing plugin '${pluginSlug}' version '${pluginVersion}'" echo "Installing plugin '${pluginSlug}' version '${pluginVersion}'"
installPlugin "${pluginSlug}" "${pluginVersion}" & installPlugin "${pluginSlug}" "${pluginVersion}" &
jobs+=($!)
else else
echo "Installing plugin '${pluginSlug}'" echo "Installing plugin '${pluginSlug}'"
installPlugin "${pluginSlug}" & installPlugin "${pluginSlug}" &
jobs+=($!)
fi fi
# Run maximum of X plugin installs in parallel # Run maximum of X plugin installs in parallel
@ -87,7 +91,10 @@ function taskInstallPlugins() {
done done
echo "Waiting for all tasks to finish..." echo "Waiting for all tasks to finish..."
wait
for pid in ${jobs[@]}; do
wait $pid
done
# Plugins are installed concurrently, so we need to verify if installed, separately # Plugins are installed concurrently, so we need to verify if installed, separately
echo "About to verify install of defined plugins" echo "About to verify install of defined plugins"
@ -111,15 +118,22 @@ main() {
echo "Automated WordPress Resources Installer" echo "Automated WordPress Resources Installer"
local jobs=()
export WP_CONTENT_PATH export WP_CONTENT_PATH
WP_PLUGINS_INSTALL_CONCURRENCY="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}" WP_PLUGINS_INSTALL_CONCURRENCY="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}"
export PLUGIN_LIST WP_PLUGINS_PATH WP_PLUGINS_INSTALL_CONCURRENCY export PLUGIN_LIST WP_PLUGINS_PATH WP_PLUGINS_INSTALL_CONCURRENCY
taskInstallPlugins "${@}" & taskInstallPlugins "${@}" &
jobs+=($!)
sleep 1
echo "Waiting for all tasks to complete" echo "Waiting for all tasks to complete"
wait
# Wait for all tasks but do not wait for the background task
for pid in ${jobs[@]}; do
wait $pid
done
return 0 return 0
} }