summaryrefslogtreecommitdiff
path: root/src/lib/image.source.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/image.source.sh')
-rw-r--r--src/lib/image.source.sh84
1 files changed, 59 insertions, 25 deletions
diff --git a/src/lib/image.source.sh b/src/lib/image.source.sh
index ccdca34..fef9345 100644
--- a/src/lib/image.source.sh
+++ b/src/lib/image.source.sh
@@ -80,7 +80,7 @@ scalephotos() {
fi
}
-wait_for_image_job_pid() {
+wait_for_parallel_job_pid() {
local -r pid="$1"; shift
local -i status=0
@@ -92,7 +92,7 @@ wait_for_image_job_pid() {
return "$status"
}
-image_job_pid_is_running() {
+parallel_job_pid_is_running() {
local -r pid="$1"; shift
local running_pid
@@ -105,10 +105,10 @@ image_job_pid_is_running() {
return 1
}
-reap_finished_image_jobs() {
- local -r image_job_pids_name="$1"; shift
+reap_finished_parallel_jobs() {
+ local -r job_pids_name="$1"; shift
# shellcheck disable=SC2178
- local -n image_job_pids_ref="$image_job_pids_name"
+ local -n job_pids_ref="$job_pids_name"
local -n failed_ref="$1"; shift
local -i reaped_status="$1"; shift
local -i has_reaped_status=1
@@ -119,13 +119,13 @@ reap_finished_image_jobs() {
mapfile -t running_pids < <(jobs -rp)
- for pid in "${image_job_pids_ref[@]}"; do
- if image_job_pid_is_running "$pid" "${running_pids[@]}"; then
+ for pid in "${job_pids_ref[@]}"; do
+ if parallel_job_pid_is_running "$pid" "${running_pids[@]}"; then
remaining_pids+=("$pid")
continue
fi
- if wait_for_image_job_pid "$pid"; then
+ if wait_for_parallel_job_pid "$pid"; then
status=0
else
status=$?
@@ -140,50 +140,84 @@ reap_finished_image_jobs() {
fi
done
- image_job_pids_ref=("${remaining_pids[@]}")
+ job_pids_ref=("${remaining_pids[@]}")
}
-wait_for_next_image_job() {
- local -r image_job_pids_name="$1"; shift
+wait_for_next_parallel_job() {
+ local -r job_pids_name="$1"; shift
local -r failed_name="$1"; shift
# shellcheck disable=SC2178
- local -n image_job_pids_ref="$image_job_pids_name"
+ local -n job_pids_ref="$job_pids_name"
local -i status=0
set +e
- wait -n "${image_job_pids_ref[@]}"
+ wait -n "${job_pids_ref[@]}"
status=$?
set -e
- reap_finished_image_jobs "$image_job_pids_name" "$failed_name" "$status"
+ reap_finished_parallel_jobs "$job_pids_name" "$failed_name" "$status"
}
-wait_for_image_job_slot() {
- local -r image_job_pids_name="$1"; shift
+wait_for_parallel_job_slot() {
+ local -r job_pids_name="$1"; shift
local -r failed_name="$1"; shift
+ local -r max_jobs="$1"; shift
# shellcheck disable=SC2178
- local -n image_job_pids_ref="$image_job_pids_name"
- local -r max_jobs="${IMAGE_JOBS:-3}"
+ local -n job_pids_ref="$job_pids_name"
- while (( ${#image_job_pids_ref[@]} >= max_jobs )); do
- wait_for_next_image_job "$image_job_pids_name" "$failed_name"
+ while (( ${#job_pids_ref[@]} >= max_jobs )); do
+ wait_for_next_parallel_job "$job_pids_name" "$failed_name"
done
}
-wait_for_image_jobs() {
+wait_for_parallel_jobs() {
# shellcheck disable=SC2178
- local -n image_job_pids_ref="$1"; shift
+ local -n job_pids_ref="$1"; shift
local -n failed_ref="$1"; shift
: "$failed_ref"
- while (( ${#image_job_pids_ref[@]} > 0 )); do
- if ! wait_for_image_job_pid "${image_job_pids_ref[0]}"; then
+ while (( ${#job_pids_ref[@]} > 0 )); do
+ if ! wait_for_parallel_job_pid "${job_pids_ref[0]}"; then
failed_ref=1
fi
- image_job_pids_ref=("${image_job_pids_ref[@]:1}")
+ job_pids_ref=("${job_pids_ref[@]:1}")
done
}
+wait_for_image_job_slot() {
+ local -r image_job_pids_name="$1"; shift
+ local -r failed_name="$1"; shift
+
+ wait_for_parallel_job_slot \
+ "$image_job_pids_name" \
+ "$failed_name" \
+ "${IMAGE_JOBS:-3}"
+}
+
+wait_for_image_jobs() {
+ local -r image_job_pids_name="$1"; shift
+ local -r failed_name="$1"; shift
+
+ wait_for_parallel_jobs "$image_job_pids_name" "$failed_name"
+}
+
+wait_for_template_render_job_slot() {
+ local -r render_job_pids_name="$1"; shift
+ local -r failed_name="$1"; shift
+
+ wait_for_parallel_job_slot \
+ "$render_job_pids_name" \
+ "$failed_name" \
+ "${IMAGE_JOBS:-3}"
+}
+
+wait_for_template_render_jobs() {
+ local -r render_job_pids_name="$1"; shift
+ local -r failed_name="$1"; shift
+
+ wait_for_parallel_jobs "$render_job_pids_name" "$failed_name"
+}
+
scale_photo() {
local -r photo="$1"; shift
local destphoto