Skip to content

Commit

Permalink
resource path ns fix
Browse files Browse the repository at this point in the history
plus flow-id increment opt, changes to schedule! and unschedule!
  • Loading branch information
ryrobes committed Dec 22, 2023
1 parent 41f357c commit a8eb0be
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 17 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
57 changes: 43 additions & 14 deletions src/flowmaps/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@

;; procedural clean up - TODO when DB
(let [flow-id (or (get opts-map :flow-id) (ut/generate-name))
flow-id (if (not (= flow-id "live-scratch-flow"))
increment-id? (get opts-map :increment-id? true)
flow-id (if increment-id? ;(not (= flow-id "live-scratch-flow"))
(str flow-id "-" (count (filter #(cstr/starts-with? % flow-id) (keys @db/channel-history))))
flow-id)] ;; don't number the scratch-flow iterations...
(swap! db/results-atom dissoc flow-id)
Expand Down Expand Up @@ -857,32 +858,60 @@
;; fn version of rest/flow-point-push
)

;; (defn schedule! [time-seq1 flowmap & args]
;; (let [[opts chan-out override] args
;; opts (if (nil? opts) {} opts)
;; times (if (and (vector? time-seq1) (keyword? (first time-seq1)))
;; (doall (take 1000 (ut/time-seq time-seq1)))
;; time-seq1)] ;; if custom time list, just send it.
;; ;(ut/ppln [:times times :time-seq time-seq1])
;; (swap! db/live-schedules conj {:flow-id (get opts :flow-id "unnamed-flow-sched")
;; :override override
;; :schedule (if (vector? time-seq1) time-seq1 [:custom-time-fn])})

;; (chime/chime-at
;; times ;; [] chime time seq, https://github.com/jarohen/chime#recurring-schedules
;; (fn [time]
;; (let [opts (merge opts {:schedule-started (str time)})]
;; (flow flowmap opts chan-out override)))
;; {:on-finished (fn [] (ut/ppln [:schedule-finished! opts time-seq1]))
;; :error-handler (fn [e] (ut/ppln [:scheduler-error e]))})))

(defn schedule! [time-seq1 flowmap & args]
(let [[opts chan-out override] args
opts (if (nil? opts) {} opts)
times (if (and (vector? time-seq1) (keyword? (first time-seq1)))
(doall (take 1000 (ut/time-seq time-seq1)))
time-seq1)] ;; if custom time list, just send it.
;(ut/ppln [:times times :time-seq time-seq1])
time-seq1)
ch (chime/chime-at
times ;; [] chime time seq, https://github.com/jarohen/chime#recurring-schedules
(fn [time]
(let [opts (merge opts {:schedule-started (str time)})]
(flow flowmap opts chan-out override)))
{:on-finished (fn [] (ut/ppln [:schedule-finished! opts time-seq1]))
:error-handler (fn [e] (ut/ppln [:scheduler-error e]))})] ;; if custom time list, just send it.
;; save channel ref for closing later w unschedule!
;; update the live schedules atom with the new schedule entry
(swap! db/live-schedules conj {:flow-id (get opts :flow-id "unnamed-flow-sched")
:override override
:schedule (if (vector? time-seq1) time-seq1 [:custom-time-fn])})

(chime/chime-at
times ;; [] chime time seq, https://github.com/jarohen/chime#recurring-schedules
(fn [time]
(let [opts (merge opts {:schedule-started (str time)})]
(flow flowmap opts chan-out override)))
{:on-finished (fn [] (ut/ppln [:schedule-finished! opts time-seq1]))
:error-handler (fn [e] (ut/ppln [:scheduler-error e]))})))
:next-times (try (vec (map str times)) (catch Exception _ times))
:schedule (if (vector? time-seq1) time-seq1 [:custom-time-fn])
:channel ch})))

(defn unschedule! [flow-id]
(let [schedule-to-remove (some #(when (= (:flow-id %) flow-id) %) @db/live-schedules)]
(when schedule-to-remove
;; Close the channel associated with the schedule
(async/close! (:channel schedule-to-remove))
;; Remove the schedule from the live schedules atom
(swap! db/live-schedules #(remove (fn [x] (= (:flow-id x) flow-id)) %)))))

;; snippets for testing -

;(web/start!) ;; boots the webserver and socket server - TODO, will be a fn to start the REST server by itself w/o dev UI
;(web/stop!)
;(db/re-init :file "mem-test") ;; persistent atoms (can even change after regular atoms have been used) - DEPRECATED

;; (flow fex/my-network {:flow-id "baloney-space-men-ahoy-mustard" :close-on-done? true :debug? false} nil {:comp1 4545 :comp2 2323}) ;; override subflow values
;(flow fex/my-network {:flow-id "baloney-space-men-ahoy-mustard" :close-on-done? true :debug? false} nil {:comp1 4545 :comp2 2323}) ;; override subflow values

;; (defn flow-waiter [in-flow]
;; (let [a (atom nil)]
Expand Down
6 changes: 3 additions & 3 deletions src/flowmaps/web.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
(defonce websocket-server (delay (jetty/run-jetty #'web-handler ring-options))) ;; delay and @call?

;;; super simple pedestal cfg for serving static SPA re-frame root...
(defn static-root [_] (ring-resp/content-type (ring-resp/resource-response "index.html" {:root "public"}) "text/html"))
(defn static-root [_] (ring-resp/content-type (ring-resp/resource-response "index.html" {:root "public-flowmaps"}) "text/html"))
(def common-interceptors [(body-params/body-params) http/html-body])

(def routes #{["/" :get (conj common-interceptors `static-root)]
Expand All @@ -49,7 +49,7 @@
; ;:script-src "*"
; :frame-ancestors "*"}
; :x-frame-options "ALLOW"}
::http/resource-path "/public"
::http/resource-path "/public-flowmaps"
:max-threads 50
::http/type :jetty
::http/host "0.0.0.0"
Expand All @@ -63,7 +63,7 @@
(def web-server (atom nil))

(defn create-web-server! []
(ut/ppln [:*web (format "starting web ui @ http://localhost:%d" 8080) "🐇" ])
(ut/ppln [:*web (format "starting flowmaps web ui debugger @ http://localhost:%d" 8080) "🐇" ])
(reset! web-server (future (http/start runnable-service))))

(defn destroy-web-server! []
Expand Down

0 comments on commit a8eb0be

Please sign in to comment.