Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2016 08:56
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jeroenvandijk/95a7d09b3c8cb7904547c95c3b4a3360 to your computer and use it in GitHub Desktop.
Repl commands for Onyx development
(ns user
(:require [ :refer [refresh]]
[com.stuartsierra.component :as component]
[onyx api
[test-helper :refer [load-config validate-enough-peers!]]]
;; Implicit requires for env
(def n-peers 10)
(defn onyx-test-env [n-peers]
(let [id (java.util.UUID/randomUUID)
config (load-config)
env-config (assoc (:env-config config) :onyx/tenancy-id id)
peer-config (assoc (:peer-config config) :onyx/tenancy-id id)]
(onyx.test-helper/map->OnyxTestEnv {:n-peers n-peers
:env-config env-config
:peer-config peer-config
:monitoring-config nil})))
(def system nil)
(defn get-peer-config []
(if-let [peer-config (:peer-config system)]
(println "Could not find :peer-config in system. Did you start the system?")))
(def last-job-id nil)
(defn submit-job [job]
(when-let [peer-config (get-peer-config)]
(let [{:keys [job-id] :as job} (onyx.api/submit-job peer-config job)]
(alter-var-root #'last-job-id (constantly job-id))
(defn kill-job [job-id]
(when-let [peer-config (get-peer-config)]
(onyx.api/kill-job peer-config job-id)
(println "Killed job: " job-id)))
(defn kill-last-job []
(if last-job-id
(do (kill-job last-job-id)
(alter-var-root #'last-job-id (constantly nil)))
(println "No job running")))
(defn init []
(alter-var-root #'system (constantly (onyx-test-env n-peers))))
(defn start []
(alter-var-root #'system component/start)
(defn stop []
(alter-var-root #'system (fn [s] (when s (component/stop s))))
(defn go []
(defn reset []
(refresh :after 'user/go))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment