From 32152898cbaebbe7d7a5f6b41be0ec8d76a08fdc Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sun, 19 Feb 2023 17:33:56 +0100 Subject: Simplify yt-dlp scheduling function further This way of trying to schedule every second day doesn't actually work. Just run every night at the same hour and randomise the minutes. --- tw/services/media.scm | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/tw/services/media.scm b/tw/services/media.scm index 34d25cf2..22a720fb 100644 --- a/tw/services/media.scm +++ b/tw/services/media.scm @@ -15,19 +15,10 @@ (define (string-or-gexp? value) (or (string? value) (gexp? value))) -(define (random-time-every-second-night day-predicate) - #~(lambda (now) - (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))))) +(define (random-minute hour) + ;; Choose a random minute of the hour. The certbot service uses + ;; `random' like this too, so it should be safe. + #~'(next-minute-from (next-hour '(#$hour)) (list (random 60)))) @@ -36,9 +27,9 @@ The service expects a @code{.yt-dlp} config directory inside this one.") (yt-dlp (package-or-false yt-dlp) "The yt-dlp package to use; or @code{#false} to use the yt-dlp script inside the config directory.") - (schedule (string-or-gexp (random-time-every-second-night 'even?)) "The mcron -schedule on which to run the download script. By default, picks a random time -between 01:00 and 06:00 every second night.") + (schedule (string-or-gexp (random-minute 4)) "The mcron schedule on which to +run the download script. By default, picks a random time between 04:00 and +05:00 every night.") (user (string "root") "The Unix user name to run the script as.")) (define (yt-dlp-cronjob config) -- cgit v1.2.3