Scheduled Tasks

Biff uses chime to execute functions on a recurring schedule. For each task, you must provide a function to run and a zero-argument schedule function which will return a list of times at which to execute the task function. The schedule can be an infinite sequence. For example, here's a task that prints out the number of users every 60 seconds:

(require '[com.biffweb :as biff :refer [q]])

(defn print-usage [{:keys [biff/db]}]
  (let [n-users (first (q db
                          '{:find (count user)
                            :where [[user :user/email]]}))]
    (println "There are" n-users "users.")))

(defn every-minute []
  (iterate #(biff/add-seconds % 60) (java.util.Date.)))

(def plugin
  {:tasks [{:task #'print-usage
            :schedule every-minute}]})

See also:

Have a question? Join the #biff channel on Clojurians Slack.

Sign up for Biff: The Newsletter
Announcements, blog posts, et cetera et cetera.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.