File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 22
33(ns temporal.side-effect
44 " Methods for managing side-effects from within workflows"
5- (:import [io.temporal.workflow Workflow]))
5+ (:require [taoensso.timbre :as log]
6+ [taoensso.nippy :as nippy]
7+ [temporal.internal.utils :refer [->Func] :as u])
8+ (:import [io.temporal.workflow Workflow]
9+ [java.time LocalTime]))
610
711(defn gen-uuid
812 " A side-effect friendly random UUID generator"
913 []
1014 (str (Workflow/randomUUID )))
15+
16+ (defn invoke
17+ " Invokes 'f' via a Temporal [SideEffect](https://docs.temporal.io/concepts/what-is-a-side-effect/)"
18+ [f]
19+ (nippy/thaw
20+ (Workflow/sideEffect u/bytes-type
21+ (->Func (fn [] (nippy/freeze (f )))))))
22+
23+ (defn now
24+ " Returns the java.time.LocalTime as a SideEffect"
25+ []
26+ (invoke #(LocalTime/now )))
Original file line number Diff line number Diff line change 1+ ; ; Copyright © 2022 Manetu, Inc. All rights reserved
2+
3+ (ns temporal.test.side-effect
4+ (:require [clojure.test :refer :all ]
5+ [taoensso.timbre :as log]
6+ [temporal.client.core :as c]
7+ [temporal.workflow :refer [defworkflow ]]
8+ [temporal.side-effect :as side-effect]
9+ [temporal.test.utils :as t])
10+ (:import [java.time LocalTime]))
11+
12+ (use-fixtures :once t/wrap-service)
13+
14+ (defworkflow side-effect-workflow
15+ [ctx {:keys [args]}]
16+ (log/info " workflow:" args)
17+ (side-effect/now ))
18+
19+ (deftest the-test
20+ (testing " Verifies that we can round-trip through start"
21+ (let [workflow (t/create-workflow side-effect-workflow)]
22+ (c/start workflow {})
23+ (is (instance? LocalTime @(c/get-result workflow))))))
You can’t perform that action at this time.
0 commit comments