From a7f985934ba6a711033de5508e8faf7a88465e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Mon, 28 Jul 2025 12:43:36 +0200 Subject: [PATCH] Add support for start-delay option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KARASZI István --- src/temporal/internal/workflow.clj | 3 +- test/temporal/test/start_delay.clj | 50 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/temporal/test/start_delay.clj diff --git a/src/temporal/internal/workflow.clj b/src/temporal/internal/workflow.clj index 1d9c2cb..d1a1d5c 100644 --- a/src/temporal/internal/workflow.clj +++ b/src/temporal/internal/workflow.clj @@ -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] diff --git a/test/temporal/test/start_delay.clj b/test/temporal/test/start_delay.clj new file mode 100644 index 0000000..79fa9b3 --- /dev/null +++ b/test/temporal/test/start_delay.clj @@ -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)))))