From ddda48dac8e373f9bc0884ffeb84605925d988e5 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 25 Jan 2021 19:33:01 +0100 Subject: sfeed_update: separate code of parallel exection and feed() into a _feed() handler This is useful to be able to reuse the code (together with using sfeed_update as an included script, coming in the next commit). --- sfeed_update | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'sfeed_update') diff --git a/sfeed_update b/sfeed_update index 96f1111..9a729e4 100755 --- a/sfeed_update +++ b/sfeed_update @@ -79,17 +79,10 @@ order() { sort -t ' ' -k1rn,1 } -# fetch and parse feed. -# feed(name, feedurl, [basesiteurl], [encoding]) -feed() { - # wait until ${maxjobs} are finished: will stall the queue if an item - # is slow, but it is portable. - [ ${signo} -ne 0 ] && return - [ $((curjobs % maxjobs)) -eq 0 ] && wait - [ ${signo} -ne 0 ] && return - curjobs=$((curjobs + 1)) - - (name="$1" +# internal handler to fetch and process a feed. +# _feed(name, feedurl, [basesiteurl], [encoding]) +_feed() { + name="$1" feedurl="$2" basesiteurl="$3" encoding="$4" @@ -160,7 +153,19 @@ feed() { # OK log "${name}" "OK" - ) & +} + +# fetch and process a feed in parallel. +# feed(name, feedurl, [basesiteurl], [encoding]) +feed() { + # wait until ${maxjobs} are finished: will stall the queue if an item + # is slow, but it is portable. + [ ${signo} -ne 0 ] && return + [ $((curjobs % maxjobs)) -eq 0 ] && wait + [ ${signo} -ne 0 ] && return + curjobs=$((curjobs + 1)) + + _feed "$@" & } cleanup() { -- cgit v1.2.3