Skip to content

Commit f9a0cca

Browse files
raszighaskins
authored andcommitted
Add support for start-delay option
Signed-off-by: KARASZI István <[email protected]>
1 parent ad76f6c commit f9a0cca

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/temporal/internal/workflow.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
:retry-options #(.setRetryOptions %1 (common/retry-options-> %2))
5454
:cron-schedule #(.setCronSchedule ^WorkflowOptions$Builder %1 %2)
5555
:memo #(.setMemo ^WorkflowOptions$Builder %1 %2)
56-
:search-attributes #(.setSearchAttributes ^WorkflowOptions$Builder %1 %2)})
56+
:search-attributes #(.setSearchAttributes ^WorkflowOptions$Builder %1 %2)
57+
:start-delay #(.setStartDelay ^WorkflowOptions$Builder %1 %2)})
5758

5859
(defn ^:no-doc wf-options->
5960
^WorkflowOptions [params]

test/temporal/test/start_delay.clj

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(ns temporal.test.start-delay
2+
(:require
3+
[clojure.test :refer :all]
4+
[temporal.client.core :as c]
5+
[temporal.test.utils :as t]
6+
[temporal.workflow :refer [defworkflow]])
7+
(:import
8+
[io.temporal.client WorkflowStub]
9+
[java.time Duration Instant]
10+
[java.time.temporal ChronoUnit TemporalAmount]))
11+
12+
(set! *warn-on-reflection* true)
13+
14+
(use-fixtures :once t/wrap-service)
15+
16+
(defworkflow delay-workflow
17+
[_args]
18+
:ok)
19+
20+
(defn create [options]
21+
(let [options (assoc options :task-queue t/task-queue)
22+
wf (c/create-workflow (t/get-client) delay-workflow options)]
23+
(c/start wf nil)
24+
wf))
25+
26+
(defn get-execution-time ^Instant [workflow]
27+
(.. ^WorkflowStub (:stub workflow)
28+
describe
29+
getExecutionTime))
30+
31+
(defn from-now ^Instant [^TemporalAmount delay]
32+
(.. (Instant/now)
33+
(plus delay)
34+
(truncatedTo ChronoUnit/SECONDS)))
35+
36+
(deftest the-test
37+
(testing "Verifies that the workflow got delayed"
38+
(let [start-delay (Duration/ofHours 2)
39+
expected (from-now start-delay)
40+
wf (create {:workflow-id "delayed-workflow"
41+
:start-delay start-delay})
42+
execution-time (get-execution-time wf)]
43+
(is (.isBefore expected execution-time)))))
44+
45+
(deftest no-delay
46+
(testing "Verifies that the workflow is not delayed per default"
47+
(let [wf (create {:workflow-id "non-delayed-workflow"})
48+
execution-time (get-execution-time wf)
49+
now (from-now (Duration/ofSeconds 1))]
50+
(is (.isAfter now execution-time)))))

0 commit comments

Comments
 (0)