diff --git a/deps.edn b/deps.edn index 9de763f..0acfdd9 100644 --- a/deps.edn +++ b/deps.edn @@ -3,7 +3,7 @@ :deps {org.clojure/clojure {:mvn/version "1.11.0"} nostromo/nostromo {:git/url "https://github.com/nosana-ci/nostromo" - :sha "0dd207fab706bda8d29e11208ef8921c9359e0bb"} + :sha "543a42aabd469af951df5a050c4a6a1ee6a5f7bc"} ;; nostromo/nostromo {:local/root "../../../nostromo"} org.clojure/tools.cli {:mvn/version "1.0.214"} diff --git a/src/nosana_node/cli.clj b/src/nosana_node/cli.clj index 6b493d7..471587d 100644 --- a/src/nosana_node/cli.clj +++ b/src/nosana_node/cli.clj @@ -94,7 +94,11 @@ "join-test-grid" {:options - [["-h" "--help"]] + [[nil "--market ADDR" "Solana address of the Test Grid market." + :default-desc "" + :default "2kNSniTBsLCioSr4dgdZh6S1JKQc8cZQvxrPWkEn1ERj" + :id :nosana-market] + ["-h" "--help"]] :usage (fn [options-summary] @@ -136,10 +140,9 @@ [] (reduce (fn [conf-map [conf-key env-var]] - (let [env-val (System/getenv env-var)] - (if env-val - (assoc conf-map conf-key env-val) - conf-map))) + (if-let [env-val (System/getenv env-var)] + (assoc conf-map conf-key env-val) + conf-map)) {} env-config)) @@ -148,8 +151,6 @@ (cond )) - - (defn use-cli "Parse CLI arguments using `tools.cli` and add to system map. @@ -171,7 +172,7 @@ (not (contains? cli-actions action)) {:exit-message (str "Unknown action " action) :ok? false} - ;; parse the inner options passed this the action + ;; parse the inner options passed to this action :else (let [{a-summary :summary a-errors :errors a-args :arguments a-options :options} (cli/parse-opts (rest arguments) (get-in cli-options [action :options]))] @@ -184,7 +185,6 @@ :else (merge options a-options))))] - (cond (:exit-message state) (do @@ -200,6 +200,7 @@ (nth (reverse [:trace :debug :info :warn :error :fatal :report]) verbosity)] + (log/set-min-level! log-level) (log/debug "Log level is " log-level)) @@ -207,8 +208,4 @@ (cond-> (-> sys (assoc :nos/action action) - (update :nos/vault merge state)) - (= "start" action) - (assoc :run-server? true) - (not= "start" action) - (:nos/start-job-loop? false)))))) + (update :nos/vault merge state))))))) diff --git a/src/nosana_node/join_test_grid.clj b/src/nosana_node/join_test_grid.clj index 2c51884..dce6f9b 100644 --- a/src/nosana_node/join_test_grid.clj +++ b/src/nosana_node/join_test_grid.clj @@ -1,10 +1,87 @@ (ns nosana-node.join-test-grid "Functions for handling the `join-test-grid` command" - (:require [nosana-node.nosana :as nos] - [nosana-node.solana :as sol])) + (:require + [taoensso.timbre :as log] + [nosana-node.nosana :as nos] + [nosana-node.solana :as sol] + [clojure.core.async :as async :refer + [!! go go-loop >! timeout chan]])) -(defn join-test-grid +(defn has-jobs? + "Check if the test grid market still has jobs." + [conf] + (let [market (nos/get-market conf)] + (and (= (:queueType market) 0) + (not-empty (:queue market))))) + +(defn get-test-grid-run + "Get run for this node on the test grid. + Will enter the market if necessary." + [conf] + (go + (if-let [run (nos/find-next-run conf)] + ;; if we already have a run we can use that + run + ;; else we will enter the market and return the run + (cond + (not (has-jobs? conf)) + {:error "There is currently no availability on the Test Grid." :ok? true} + + :else + (let [_ (println "Entering the market") + sig (nos/enter-market conf) + tx ( (- (flow/current-time) timestamp) (* 60 15))) (defn find-next-run - "Find all assigned runs and return the first assigned to our - market. Returns a tuple of [run-address run-data]." + "Find the first run assigned to us in the configure market. + Returns a tuple of [run-address run-data]." [conf] (let [runs (find-my-runs conf)] (loop [[[run-addr run] & rst] runs] @@ -658,6 +659,15 @@ [run-addr run] (recur rst))))))) +(defn subscribe-to-finished-flows + "Return a chan that publishes messages of finished flows." + [{:nos/keys [flow-chan-mult]}] + (let [finish-flow-chan (chan) + flow-chan-tap (chan)] + (async/tap flow-chan-mult flow-chan-tap) + (async/sub (async/pub flow-chan-tap first) :finished finish-flow-chan) + finish-flow-chan)) + (defn work-loop "Main loop." [{:nos/keys [conf poll-delay exit-chan flow-chan-mult work-loop-chan] :as system}]