Skip to content

Commit

Permalink
Add layout of join-test-grid command
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisses committed Nov 22, 2023
1 parent abb045f commit f8a6098
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 48 deletions.
8 changes: 5 additions & 3 deletions dev/src/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
[nosana-node.system :as nos-sys
:refer [start-system
use-jetty
use-wrap-ctx]]
use-wrap-ctx
use-nrepl]]
[nosana-node.util :refer [bytes->hex hex->bytes base58] :as util]
[nos.ops.docker :as docker]
[aero.core :refer (read-config)]
Expand All @@ -22,7 +23,6 @@
[nos.store :as store]
[nos.system :refer [use-nostromo]]
[clojure.java.io :as io]
[nosana-node.main :as main]
[nosana-node.cli :as cli]
[nosana-node.pipeline :as pl]
[nosana-node.nosana :as nos :refer [use-nosana]]
Expand All @@ -44,15 +44,17 @@
(->
(update sys :nos/vault merge config)
(assoc :run-server? true
:nos/start-job-loop? true))))
:nos/start-job-loop? false))))

(defn go []
(taoensso.timbre/set-min-level! :info)
(start-system
system
{:http/handler #'nos-sys/handler
:system/components [use-vault
use-config
store/use-fs-store
use-nrepl
use-nostromo
use-nosana
use-wrap-ctx
Expand Down
11 changes: 7 additions & 4 deletions src/nosana_node/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
(not (contains? cli-actions action))
{:exit-message (str "Unknown action " action) :ok? false}

;; parse the arguments for this action
;; parse the inner options passed this the 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]))]
Expand Down Expand Up @@ -204,7 +204,10 @@

;; merge CLI over existing config
(cond->
(update sys :nos/vault merge state)
(-> sys
(assoc :nos/action action)
(update :nos/vault merge state))
(= "start" action)
(assoc :run-server? true
:nos/start-job-loop? true))))))
(assoc :run-server? true)
(not= "start" action)
(:nos/start-job-loop? false))))))
10 changes: 10 additions & 0 deletions src/nosana_node/join_test_grid.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(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]))

(defn join-test-grid
"Handle the `join-test-grid` command."
[system]
(println "test grid")
)
60 changes: 27 additions & 33 deletions src/nosana_node/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@

(ns nosana-node.main
(:require
[nosana-node.nosana :as nosana :refer [use-nosana]]
[nosana-node.nosana :as nosana :refer [use-nosana work-loop]]
[nos.core :as flow]
[clojure.core.async :refer [<!!]]
[nosana-node.system :refer [start-system use-when] :as nos-sys]
[nosana-node.pipeline :as pipeline]
[nosana-node.cli :as cli]
nosana-node.gitlab
nos.ops.docker
[nos.store :as store]
[nosana-node.join-test-grid :refer [join-test-grid]]
[nos.vault :refer [use-vault]]
[nos.system :refer [use-nostromo]]
[clojure.java.io :as io]

[clojure.string :as string]
[nrepl.server :as nrepl-server]
[cider.nrepl :refer (cider-nrepl-handler)]))
[clojure.string :as string]))

(defonce system (atom nil))

Expand All @@ -35,15 +34,6 @@
:chan (:nos/flow-chan @system)
:vault (:nos/vault @system)})

(defn use-nrepl [system]
(let [port 7888
socket (nrepl-server/start-server
:bind "0.0.0.0"
:port port
:handler cider-nrepl-handler)]
(log/info "Started nrepl server on port " port)
(update system :system/stop conj #(.close socket))))

(defn use-pipeline [{:keys [nos/vault] :as system}]
(let [dir (System/getProperty "user.dir")]
(try
Expand All @@ -53,26 +43,30 @@

(defn -main [& args]
(try
(start-system
system
{:http/handler #'nos-sys/handler
:system/components [use-vault
cli/use-cli
store/use-fs-store
(use-when :run-server?
(let [sys
(start-system
system
{:http/handler #'nos-sys/handler
:system/components [use-vault
cli/use-cli
store/use-fs-store
(use-when :run-server?
;; use-nrepl
use-nostromo
use-nosana
nos-sys/use-wrap-ctx
)
(use-when #(not (:run-server? %))
use-pipeline)]
:system/profile :prod
:cli-args args
:nos/log-dir "/tmp/logs"
:nos/store-path "/tmp/store"
:nos/vault-path (io/resource "config.edn")})

use-nostromo
use-nosana
nos-sys/use-wrap-ctx
)
(use-when #(not (:run-server? %))
use-pipeline)]
:system/profile :prod
:cli-args args
:nos/log-dir "/tmp/logs"
:nos/store-path "/tmp/store"
:nos/start-job-loop true
:nos/vault-path (io/resource "config.edn")})]
(case (:nos/action sys)
"start" (<!! (work-loop sys))
"join-test-grid") (join-test-grid sys))
(catch Exception e
(do
(log/log :trace e)
Expand Down
12 changes: 4 additions & 8 deletions src/nosana_node/nosana.clj
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@

(defn work-loop
"Main loop."
[conf {:nos/keys [poll-delay exit-chan flow-chan-mult work-loop-chan] :as system}]
[{:nos/keys [conf poll-delay exit-chan flow-chan-mult work-loop-chan] :as system}]
(let [finish-flow-chan (chan)
flow-chan-tap (chan)]
;; we subscribe to all `flow-chan` messages that start with `:finished`
Expand Down Expand Up @@ -726,7 +726,8 @@
(when enter-sig
(let [tx (<! (sol/await-tx< enter-sig (:network conf)))]
(when (:err (:meta tx))
(log :error "Error: could not enter the market."))))
(log :error "Error: could not enter the market")
(log :debug tx))))
(recur nil last-health-check true)))))))))

(defn use-nosana
Expand Down Expand Up @@ -788,15 +789,10 @@
;; (async/put! exit-ch true)
(-> system
(assoc
:nos/loop-chan
(when (and (:nos/start-job-loop? system) (= :success status))
(<!! (work-loop conf (merge system
{:nos/exit-chan exit-ch
:nos/work-loop-chan work-loop-ch
:nos/poll-delay (:poll-delay-ms vault)}))))
:nos/exit-chan exit-ch
:nos/work-loop-chan work-loop-ch
:nos/poll-delay (:poll-delay-ms vault)
:nos/conf conf
:nos/solana-network (:network conf)
:nos/programs (:programs conf))
(update :system/stop conj #(put! exit-ch true)))))
11 changes: 11 additions & 0 deletions src/nosana_node/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@
[clojure.string :as string]
[taoensso.timbre :as log]
[nosana-node.cors :refer [wrap-all-cors]]
[nrepl.server :as nrepl-server]
[cider.nrepl :refer (cider-nrepl-handler)]
[ring.util.codec :refer [form-decode]])
(:import [org.p2p.solanaj.utils TweetNaclFast TweetNaclFast$Signature]))

(defn use-nrepl [system]
(let [port 7888
socket (nrepl-server/start-server
:bind "0.0.0.0"
:port port
:handler cider-nrepl-handler)]
(log/info "Started nrepl server on port " port)
(update system :system/stop conj #(.close socket))))

(defn stop-system [{:keys [system/stop]}]
(doseq [f stop]
(log/info "stopping:" (str f))
Expand Down

0 comments on commit f8a6098

Please sign in to comment.