Skip to content
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

Add support for versioning #49

Merged
merged 1 commit into from
Mar 7, 2024
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This Clojure SDK is a framework for authoring Workflows and Activities in Clojur

**Alpha**

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.
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.

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

Expand Down
14 changes: 7 additions & 7 deletions src/temporal/client/worker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Initializes a worker instance, suitable for real connections or unit-testing wit
{:activities (a/import-dispatch activities) :workflows (w/import-dispatch workflows)})]
(log/trace "init:" dispatch)
(.registerActivitiesImplementations worker (to-array [(a/dispatcher ctx (:activities dispatch))]))
(.addWorkflowImplementationFactory worker DynamicWorkflowProxy
(u/->Func
(fn []
(new DynamicWorkflowProxy
(reify DynamicWorkflow
(execute [_ args]
(w/execute ctx (:workflows dispatch) args)))))))))
(.registerWorkflowImplementationFactory worker DynamicWorkflowProxy
(u/->Func
(fn []
(new DynamicWorkflowProxy
(reify DynamicWorkflow
(execute [_ args]
(w/execute ctx (:workflows dispatch) args)))))))))
(def worker-factory-options
"
Options for configuring the worker-factory (See [[start]])
Expand Down
3 changes: 2 additions & 1 deletion src/temporal/internal/workflow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
{:namespace (.getNamespace d)
:workflow-id (.getWorkflowId d)
:run-id (.getRunId d)
:workflow-type (.getWorkflowType d)}))
:workflow-type (.getWorkflowType d)
:attempt (.getAttempt d)}))

(defn get-info []
(d/datafy (Workflow/getInfo)))
Expand Down
7 changes: 7 additions & 0 deletions src/temporal/workflow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
[^Duration duration]
(Workflow/sleep duration))

(def default-version Workflow/DEFAULT_VERSION)

(defn get-version
"Used to safely perform backwards incompatible changes to workflow definitions"
[change-id min max]
(Workflow/getVersion (u/namify change-id) min max))

(defn register-query-handler!
"
Registers a DynamicQueryHandler listener that handles queries sent to the workflow, using [[temporal.client.core/query]].
Expand Down
32 changes: 32 additions & 0 deletions test/temporal/test/versioning.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
;; Copyright © Manetu, Inc. All rights reserved

(ns temporal.test.versioning
(:require [clojure.test :refer :all]
[taoensso.timbre :as log]
[temporal.client.core :as c]
[temporal.workflow :refer [defworkflow] :as w]
[temporal.activity :refer [defactivity] :as a]
[temporal.test.utils :as t]))

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

;; Only serves to generate events in our history
(defactivity versioned-activity
[ctx args]
:ok)

(defworkflow versioned-workflow
[args]
(log/info "versioned-workflow:" args)
@(a/invoke versioned-activity args)

(case (w/get-version ::test w/default-version 1)
w/default-version @(a/invoke versioned-activity args)
1 @(a/local-invoke versioned-activity args)))

(deftest the-test
(testing "Verifies that we can version a workflow"
(let [client (t/get-client)
wf (c/create-workflow client versioned-workflow {:task-queue t/task-queue :workflow-id "test"})]
(c/start wf {})
(is (= @(c/get-result wf) :ok)))))