We use the Quartz library for job scheduling in our Clojure projects. It's nice to have this done within the JVM so that we can easily deploy to a new server without needing to configure cron (and the differences with cron across platforms...).
http://www.quartz-scheduler.org/ If you want to call the run-import-process function every morning at 6am, it looks like this: (ns foo.core (:import [org.quartz.impl StdSchedulerFactory] [org.quartz CronTrigger JobDetail] [java.io File])) (defn run-import-process [] (println "running import process...")) (def scheduler* (atom nil)) (def CRON-STR-6AM "0 0 6 * * ?") ; every day at 6am ;(def CRON-STR-6AM "* * * * * ?") ; every second, for testing (deftype ImportJob [] org.quartz.Job (execute [this context] (run-import-process))) (defn start-import-manager [] (let [scheduler (StdSchedulerFactory/getDefaultScheduler) trigger (CronTrigger. "import-trigger" "import" CRON-STR-6AM) job (JobDetail. "import-job" "import" ImportJob)] (reset! scheduler* scheduler) (.scheduleJob scheduler job trigger) (.start scheduler))) (defn stop-import-manager [& [wait?]] (if wait? (.shutdown @scheduler* true) (.shutdown @scheduler*))) Cheers, Jeff On Jan 7, 6:13 pm, Trevor <tcr1...@gmail.com> wrote: > What's the best way to kick off Clojure code at scheduled times? I > have some that would run once a day. Some that might run 2 or 3 times > a day based upon a test being met. > > 1. I could write a function that sleeps an interval, check the time > differential to perform a time-box triggered function, but would that > consume too much memory?, cause long term problems? > > 2. I could use quartz, but that seems like overkill. > > 3. I could set a job-schedule using the OS to run a clojure script. > I'd rather not, I would like to do things like send emails / check > status via web app (making option 1 more appealing). > > I'm looking for input/guidance. What are your experiences? > > Thanks, -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en