Skip to content

Instantly share code, notes, and snippets.

@jphackworth
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jphackworth/9976671 to your computer and use it in GitHub Desktop.
Save jphackworth/9976671 to your computer and use it in GitHub Desktop.
Basic queuing with Lamina
;;; Lamina queueing
(def job-queue (lamina/channel))
(def worker-interval (atom 250))
(defn consume-jobs []
(let [{:keys [c f args] :as msg}
@(lamina/read-channel job-queue)]
(Thread/sleep @worker-interval)
(lamina/enqueue c (apply f args))))
(defn job-consumer []
(doall (repeatedly consume-jobs)))
(defn start-job-consumer []
(-> (Thread. job-consumer) .start))
; FIXME: Enqueue needs job-consumer thread to have already been started
(defn add-to-queue [f & args]
(lamina/run-pipeline (lamina/channel)
(fn [ch]
(lamina/enqueue job-queue {:c ch :f f :args args})
(lamina/read-channel ch))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment