Line data Source code
1 4 : (ns matchscore.jobs.scheduler
2 : (:require
3 : [goose.client :as c]
4 : [taoensso.telemere :as t]))
5 :
6 :
7 4 : (defn schedule-job
8 : "Schedules a Goose job. Optional opts map `{:delay-seconds n :args [...]}`,
9 : or a bare number which is treated as `:delay-seconds`. `args` is a vector
10 : of arguments forwarded to the job function (after the standard
11 : system-components first arg)."
12 5 : ([goose job-sym] (schedule-job goose job-sym {}))
13 : ([goose job-sym opts-or-delay]
14 3 : (when goose
15 1 : (let [{:keys [delay-seconds args]
16 : :or {args []}}
17 8 : (if (number? opts-or-delay) {:delay-seconds opts-or-delay} opts-or-delay)
18 3 : client-opts (:client-opts goose)]
19 2 : (if delay-seconds
20 7 : (apply c/perform-in-sec client-opts delay-seconds job-sym args)
21 6 : (apply c/perform-async client-opts job-sym args))
22 92 : (t/log!
23 : :info
24 3 : (str
25 : "Scheduled Goose job: "
26 3 : (name job-sym)
27 8 : (when delay-seconds (str " in " delay-seconds "s"))
28 4 : (when (seq args) (str " args=" (count args)))))))))
|