File tree Expand file tree Collapse file tree 3 files changed +50
-8
lines changed Expand file tree Collapse file tree 3 files changed +50
-8
lines changed Original file line number Diff line number Diff line change 32
32
(rx state signal-name)))
33
33
34
34
(defn <!
35
- " Light-weight/parking receive of a single message"
35
+ " Light-weight/parking receive of a single message with an optional timeout "
36
36
([state] (<! state ::default ))
37
- ([state signal-name]
38
- (log/trace " waiting on:" signal-name)
39
- (w/await #(not (is-empty? state signal-name)))
40
- (rx state signal-name)))
37
+ ([state signal-name] (<! state signal-name nil ))
38
+ ([state signal-name timeout]
39
+ (log/trace " waiting on:" signal-name " with timeout" timeout)
40
+ (let [pred #(not (is-empty? state signal-name))]
41
+ (if (some? timeout)
42
+ (do
43
+ (when (w/await timeout pred)
44
+ (rx state signal-name)))
45
+ (do
46
+ (w/await pred)
47
+ (rx state signal-name))))))
41
48
42
49
(defn >!
43
50
" Sends `payload` to `workflow-id` via signal `signal-name`."
Original file line number Diff line number Diff line change 6
6
[temporal.internal.utils :as u]
7
7
[temporal.internal.workflow :as w])
8
8
(:import [io.temporal.workflow Workflow]
9
- [java.util.function Supplier]))
9
+ [java.util.function Supplier]
10
+ [java.time Duration]))
10
11
11
12
(defn get-info
12
13
" Return info about the current workflow"
13
14
[]
14
15
(w/get-info ))
15
16
16
17
(defn- ->supplier
17
- [f]
18
+ ^Supplier [f]
18
19
(reify Supplier
19
20
(get [_]
20
21
(f ))))
23
24
" Efficiently parks the workflow until 'pred' evaluates to true. Re-evaluates on each state transition"
24
25
([pred]
25
26
(Workflow/await (->supplier pred)))
26
- ([duration pred]
27
+ ([^Duration duration pred]
27
28
(Workflow/await duration (->supplier pred))))
28
29
29
30
(defmacro defworkflow
Original file line number Diff line number Diff line change
1
+ ; ; Copyright © 2022 Manetu, Inc. All rights reserved
2
+
3
+ (ns temporal.test.signal-timeout
4
+ (:require [clojure.test :refer :all ]
5
+ [taoensso.timbre :as log]
6
+ [temporal.client.core :refer [>!] :as c]
7
+ [temporal.signals :refer [<!]]
8
+ [temporal.workflow :refer [defworkflow ]]
9
+ [temporal.test.utils :as t])
10
+ (:import [java.time Duration]))
11
+
12
+ (use-fixtures :once t/wrap-service)
13
+
14
+ (def signal-name ::signal )
15
+
16
+ (defworkflow timeout-workflow
17
+ [ctx {:keys [signals] :as args}]
18
+ (log/info " timeout-workflow:" args)
19
+ (or (<! signals signal-name (Duration/ofSeconds 1 ))
20
+ :timed-out ))
21
+
22
+ (defn create []
23
+ (let [wf (c/create-workflow (t/get-client ) timeout-workflow {:task-queue t/task-queue})]
24
+ (c/start wf nil )
25
+ wf))
26
+
27
+ (deftest the-test
28
+ (testing " Verifies that signals may timeout properly"
29
+ (let [wf (create )]
30
+ (is (= @(c/get-result wf) :timed-out ))))
31
+ (testing " Verifies that signals are received properly even when a timeout is requested"
32
+ (let [wf (create )]
33
+ (>! wf ::signal " Hi, Bob" )
34
+ (is (= @(c/get-result wf) " Hi, Bob" )))))
You can’t perform that action at this time.
0 commit comments