Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Repl commands for Onyx development
(ns user
(:require [clojure.tools.namespace.repl :refer [refresh]]
[com.stuartsierra.component :as component]
[onyx api
[test-helper :refer [load-config validate-enough-peers!]]]
;; Implicit requires for env
[onyx.plugin.seq]
))
(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)]
peer-config
(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))
job)))
(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)
:started)
(defn stop []
(alter-var-root #'system (fn [s] (when s (component/stop s))))
:stopped)
(defn go []
(init)
(start))
(defn reset []
(stop)
(refresh :after 'user/go))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment