diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/album.source.sh | 4 | ||||
| -rw-r--r-- | src/lib/image.source.sh | 84 | ||||
| -rw-r--r-- | src/photoalbum.default.conf | 2 |
3 files changed, 62 insertions, 28 deletions
diff --git a/src/lib/album.source.sh b/src/lib/album.source.sh index 886bd81..0efff6e 100644 --- a/src/lib/album.source.sh +++ b/src/lib/album.source.sh @@ -512,7 +512,7 @@ queue_album_view_render_job() { # shellcheck disable=SC2178 local -n render_failed_ref="$1"; shift - wait_for_image_job_slot render_job_pids_ref render_failed_ref + wait_for_template_render_job_slot render_job_pids_ref render_failed_ref render_photo_view_and_details \ "$photos_dir" \ "$blurs_dir" \ @@ -531,7 +531,7 @@ wait_for_album_view_render_jobs() { # shellcheck disable=SC2178 local -n render_failed_ref="$1"; shift - wait_for_image_jobs render_job_pids_ref render_failed_ref + wait_for_template_render_jobs render_job_pids_ref render_failed_ref if (( render_failed_ref != 0 )); then return 1 fi 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 diff --git a/src/photoalbum.default.conf b/src/photoalbum.default.conf index 6fad282..b6f23a2 100644 --- a/src/photoalbum.default.conf +++ b/src/photoalbum.default.conf @@ -7,7 +7,7 @@ THUMBHEIGHT=300 HEIGHT=1200 # Max previews per page. MAXPREVIEWS=40 -# Parallel ImageMagick jobs for photo, thumbnail, and blur processing. +# Parallel jobs for image processing and HTML template rendering. IMAGE_JOBS=3 # Timeout in seconds for each ImageMagick command. IMAGEMAGICK_TIMEOUT=60 |
