Skip to content

Commit 9f0e520

Browse files
committed
Add support for versioning
Signed-off-by: Greg Haskins <[email protected]>
1 parent e128500 commit 9f0e520

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This Clojure SDK is a framework for authoring Workflows and Activities in Clojur
1111

1212
**Alpha**
1313

14-
This SDK is battle-tested and used in production but is undergoing active development and is subject to breaking changes (*). Some significant features (Versioning, Queries, and Child-Workflows, etc) are missing/incomplete.
14+
This SDK is battle-tested and used in production but is undergoing active development and is subject to breaking changes (*). Some significant features such as Child-Workflows and Schedules are missing/incomplete.
1515

1616
> (*) We will always bump at least the minor version when breaking changes are introduced and include a release note.
1717

src/temporal/client/worker.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Initializes a worker instance, suitable for real connections or unit-testing wit
2121
{:activities (a/import-dispatch activities) :workflows (w/import-dispatch workflows)})]
2222
(log/trace "init:" dispatch)
2323
(.registerActivitiesImplementations worker (to-array [(a/dispatcher ctx (:activities dispatch))]))
24-
(.addWorkflowImplementationFactory worker DynamicWorkflowProxy
25-
(u/->Func
26-
(fn []
27-
(new DynamicWorkflowProxy
28-
(reify DynamicWorkflow
29-
(execute [_ args]
30-
(w/execute ctx (:workflows dispatch) args)))))))))
24+
(.registerWorkflowImplementationFactory worker DynamicWorkflowProxy
25+
(u/->Func
26+
(fn []
27+
(new DynamicWorkflowProxy
28+
(reify DynamicWorkflow
29+
(execute [_ args]
30+
(w/execute ctx (:workflows dispatch) args)))))))))
3131
(def worker-factory-options
3232
"
3333
Options for configuring the worker-factory (See [[start]])

src/temporal/internal/workflow.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
{:namespace (.getNamespace d)
3535
:workflow-id (.getWorkflowId d)
3636
:run-id (.getRunId d)
37-
:workflow-type (.getWorkflowType d)}))
37+
:workflow-type (.getWorkflowType d)
38+
:attempt (.getAttempt d)}))
3839

3940
(defn get-info []
4041
(d/datafy (Workflow/getInfo)))

src/temporal/workflow.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
[^Duration duration]
3535
(Workflow/sleep duration))
3636

37+
(def default-version Workflow/DEFAULT_VERSION)
38+
39+
(defn get-version
40+
"Used to safely perform backwards incompatible changes to workflow definitions"
41+
[change-id min max]
42+
(Workflow/getVersion (u/namify change-id) min max))
43+
3744
(defn register-query-handler!
3845
"
3946
Registers a DynamicQueryHandler listener that handles queries sent to the workflow, using [[temporal.client.core/query]].

test/temporal/test/versioning.clj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
;; Copyright © Manetu, Inc. All rights reserved
2+
3+
(ns temporal.test.versioning
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.activity :refer [defactivity] :as a]
9+
[temporal.test.utils :as t]))
10+
11+
(use-fixtures :once t/wrap-service)
12+
13+
;; Only serves to generate events in our history
14+
(defactivity versioned-activity
15+
[ctx args]
16+
:ok)
17+
18+
(defworkflow versioned-workflow
19+
[args]
20+
(log/info "versioned-workflow:" args)
21+
@(a/invoke versioned-activity args)
22+
23+
(case (w/get-version ::test w/default-version 1)
24+
w/default-version @(a/invoke versioned-activity args)
25+
1 @(a/local-invoke versioned-activity args)))
26+
27+
(deftest the-test
28+
(testing "Verifies that we can version a workflow"
29+
(let [client (t/get-client)
30+
wf (c/create-workflow client versioned-workflow {:task-queue t/task-queue :workflow-id "test"})]
31+
(c/start wf {})
32+
(is (= @(c/get-result wf) :ok)))))

0 commit comments

Comments
 (0)