From 9989ab2f85bafd3b1f8fdacc02fce9e3c4b7d90a Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sun, 19 Feb 2023 16:56:50 +0100 Subject: Simplify yt-dlp scheduling function --- tw/services/media.scm | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'tw/services/media.scm') diff --git a/tw/services/media.scm b/tw/services/media.scm index 5fd5b2b5..910983a1 100644 --- a/tw/services/media.scm +++ b/tw/services/media.scm @@ -17,18 +17,17 @@ (define (random-time-every-second-night day-predicate) #~(lambda (now) - (let* ((even-day - (if (#$day-predicate (tm:yday (localtime now))) - now - (next-day-from now))) - (deterministic-value - (number->string (tm:yday (localtime even-day))))) - ;; Between 1 and 6 a.m., randomly, but deterministically for each - ;; day (to avoid runs being skipped in case mcron is restarted). - ;; (random 6 (seed->random-state yday)) isn't chaotic enough. - (next-minute-from - (next-hour-from even-day (list (1+ (string-hash deterministic-value 6)))) - (list (string-hash deterministic-value 60)))))) + (next-minute-from + (next-hour-from + ;; If today's day number satisfies `day-predicate' (e.g. `even?'), + ;; then run today, else tomorrow. + (if (#$day-predicate (tm:yday (localtime now))) + now + (next-day-from now)) + ;; Between 1 and 6 a.m., randomly. The certbot service uses `random' + ;; like this too, so it should be safe. + (list (1+ (random 6)))) + (list (random 60))))) -- cgit v1.2.3