From e52e5ea5494319f158e9d9c1425b16b9986e929a Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 6 Apr 2018 19:54:03 +0200 Subject: rss_staggered --- odin/strm.nix | 8 +++++--- odin/strm/rss_staggered | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100755 odin/strm/rss_staggered diff --git a/odin/strm.nix b/odin/strm.nix index 8c88514e..71d93011 100644 --- a/odin/strm.nix +++ b/odin/strm.nix @@ -1,4 +1,4 @@ -{ stdenv, zsh, ffmpeg-full, youtube-dl, pv, notmuch }: +{ stdenv, zsh, ffmpeg-full, youtube-dl, pv, notmuch, rss2email }: stdenv.mkDerivation { name = "strm"; @@ -6,7 +6,7 @@ stdenv.mkDerivation { phases = [ "unpackPhase" "buildPhase" "installPhase" ]; - inherit zsh pv notmuch; + inherit zsh pv notmuch rss2email; ffmpeg = ffmpeg-full; youtubedl = youtube-dl; @@ -16,6 +16,7 @@ stdenv.mkDerivation { substituteAllInPlace send_media substituteAllInPlace cache_media substituteAllInPlace send_kitty + substituteAllInPlace rss_staggered ''; installPhase = '' @@ -26,6 +27,7 @@ stdenv.mkDerivation { cleanup_youtube \ send_media \ cache_media \ - send_kitty + send_kitty \ + rss_staggered ''; } diff --git a/odin/strm/rss_staggered b/odin/strm/rss_staggered new file mode 100755 index 00000000..54bbd1a3 --- /dev/null +++ b/odin/strm/rss_staggered @@ -0,0 +1,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 -- cgit v1.2.3