Skip to content

feat: support start-delay option #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/temporal/internal/workflow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
:retry-options #(.setRetryOptions %1 (common/retry-options-> %2))
:cron-schedule #(.setCronSchedule ^WorkflowOptions$Builder %1 %2)
:memo #(.setMemo ^WorkflowOptions$Builder %1 %2)
:search-attributes #(.setSearchAttributes ^WorkflowOptions$Builder %1 %2)})
:search-attributes #(.setSearchAttributes ^WorkflowOptions$Builder %1 %2)
:start-delay #(.setStartDelay ^WorkflowOptions$Builder %1 %2)})

(defn ^:no-doc wf-options->
^WorkflowOptions [params]
Expand Down
50 changes: 50 additions & 0 deletions test/temporal/test/start_delay.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
(ns temporal.test.start-delay
(:require
[clojure.test :refer :all]
[temporal.client.core :as c]
[temporal.test.utils :as t]
[temporal.workflow :refer [defworkflow]])
(:import
[io.temporal.client WorkflowStub]
[java.time Duration Instant]
[java.time.temporal ChronoUnit TemporalAmount]))

(set! *warn-on-reflection* true)

(use-fixtures :once t/wrap-service)

(defworkflow delay-workflow
[_args]
:ok)

(defn create [options]
(let [options (assoc options :task-queue t/task-queue)
wf (c/create-workflow (t/get-client) delay-workflow options)]
(c/start wf nil)
wf))

(defn get-execution-time ^Instant [workflow]
(.. ^WorkflowStub (:stub workflow)
describe
getExecutionTime))

(defn from-now ^Instant [^TemporalAmount delay]
(.. (Instant/now)
(plus delay)
(truncatedTo ChronoUnit/SECONDS)))

(deftest the-test
(testing "Verifies that the workflow got delayed"
(let [start-delay (Duration/ofHours 2)
expected (from-now start-delay)
wf (create {:workflow-id "delayed-workflow"
:start-delay start-delay})
execution-time (get-execution-time wf)]
(is (.isBefore expected execution-time)))))

(deftest no-delay
(testing "Verifies that the workflow is not delayed per default"
(let [wf (create {:workflow-id "non-delayed-workflow"})
execution-time (get-execution-time wf)
now (from-now (Duration/ofSeconds 1))]
(is (.isAfter now execution-time)))))