Created
June 15, 2016 08:56
-
-
Save jeroenvandijk/95a7d09b3c8cb7904547c95c3b4a3360 to your computer and use it in GitHub Desktop.
Repl commands for Onyx development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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