001 (ns cmp.worker.write-exchange
002 ^{:author "wactbprot"
003 :doc "wait worker."}
004 (:require [cmp.config :as cfg]
005 [cmp.exchange :as exch]
006 [com.brunobonacci.mulog :as mu]
007 [cmp.st-mem :as st]))
008
009 (defn write-exchange!
010 "Writes the `:Value` to the exchange.
011
012 ```clojure
013 (write-exchange! {:Value {:a 1 :b 2} :MpName \"ref\"})
014 ;;
015 (st/key->val \"ref@exchange@b\")
016 ;; 2
017 ```"
018 [{val :Value mp-id :MpName state-key :StateKey exch-path :ExchangePath :as task}]
019 (st/set-state! state-key :working)
020 (let [ret (exch/to! mp-id val exch-path)]
021 (if (:ok ret)
022 (st/set-state! state-key (if (exch/stop-if task) :executed :ready) "wrote to exchange")
023 (st/set-state! state-key :error "error on attempt to write exchange"))))