summaryrefslogtreecommitdiff
path: root/odin/strm/rss_staggered
blob: 54bbd1a341001c55b20fe81f80ef0184fc80ec8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!@zsh@/bin/zsh

delta_t=20
interval=3600

staggerFile=~/.rss-stagger

[[ "${FLOCKER}" != "$0" ]] && exec env FLOCKER="$0" flock -x "${staggerFile}" "$0" "$@" || :

feeds=$(@rss2email@/bin/r2e list | awk -F ':' 'END { print $1; }')
max=$(($feeds + 1))
num=$(((max * delta_t) / interval))
[[ $num -lt 1 ]] && num=1

now=$(cat ${staggerFile} || echo 0)
now=$((now % max))

typeset -a run
run=()
typeset -a names
names=()

n=0

for i in $(seq $((now + 1)) $((now + num + 1))); do
    n=$((i % max))
    run+=$n
done

echo $n >! ${staggerFile}

exec @rss2email@/bin/r2e run $run