Skip to content

Commit 2c4272b

Browse files
committed
Add workflow/sleep
Signed-off-by: Greg Haskins <[email protected]>
1 parent 51cbc5f commit 2c4272b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/temporal/workflow.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
([^Duration duration pred]
2828
(Workflow/await duration (->supplier pred))))
2929

30+
(defn sleep
31+
"Efficiently parks the workflow for 'duration'"
32+
[^Duration duration]
33+
(Workflow/sleep duration))
34+
3035
(defmacro defworkflow
3136
"
3237
Defines a new workflow, similar to defn, expecting a 2-arity parameter list and body. Should evaluate to something

test/temporal/test/sleep.clj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
;; Copyright © 2022 Manetu, Inc. All rights reserved
2+
3+
(ns temporal.test.sleep
4+
(:require [clojure.test :refer :all]
5+
[taoensso.timbre :as log]
6+
[temporal.client.core :as c]
7+
[temporal.workflow :refer [defworkflow] :as w]
8+
[temporal.test.utils :as t])
9+
(:import [java.time Duration]))
10+
11+
(use-fixtures :once t/wrap-service)
12+
13+
(defworkflow sleep-workflow
14+
[ctx {:keys [signals] :as args}]
15+
(log/info "sleep-workflow:" args)
16+
(w/sleep (Duration/ofSeconds 1))
17+
:ok)
18+
19+
(defn create []
20+
(let [wf (c/create-workflow (t/get-client) sleep-workflow {:task-queue t/task-queue})]
21+
(c/start wf nil)
22+
wf))
23+
24+
(deftest the-test
25+
(testing "Verifies that signals may timeout properly"
26+
(let [wf (create)]
27+
(is (= @(c/get-result wf) :ok)))))

0 commit comments

Comments
 (0)