Skip to content

Commit aad2893

Browse files
committed
Add side-effect/invoke and side-effect/now
Signed-off-by: Greg Haskins <[email protected]>
1 parent 5563fac commit aad2893

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/temporal/side_effect.clj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
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)))

test/temporal/test/side_effect.clj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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))))))

0 commit comments

Comments
 (0)