Skip to content

Commit 1576bf4

Browse files
ghaskinsecb
authored andcommitted
Update to temporal-sdk 1.27.0 and add support for vthreads
Signed-off-by: Greg Haskins <[email protected]>
1 parent 436b82c commit 1576bf4

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

project.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
[jonase/eastwood "1.3.0"]
1313
[lein-codox "0.10.8"]]
1414
:dependencies [[org.clojure/clojure "1.11.4"]
15-
[org.clojure/core.async "1.6.681"]
16-
[io.temporal/temporal-sdk "1.25.1"]
17-
[io.temporal/temporal-testing "1.25.1"]
18-
[com.taoensso/encore "3.117.0"]
19-
[com.taoensso/timbre "6.5.0"]
15+
[org.clojure/core.async "1.7.701"]
16+
[io.temporal/temporal-sdk "1.27.0"]
17+
[io.temporal/temporal-testing "1.27.0"]
18+
[com.taoensso/encore "3.133.0"]
19+
[com.taoensso/timbre "6.6.1"]
2020
[com.taoensso/nippy "3.4.2"]
2121
[funcool/promesa "9.2.542"]
2222
[medley "1.4.0"]
@@ -31,7 +31,7 @@
3131
:profiles {:dev {:dependencies [[org.clojure/tools.namespace "1.5.0"]
3232
[eftest "0.6.0"]
3333
[mockery "0.1.4"]
34-
[io.temporal/temporal-opentracing "1.25.1"]]
34+
[io.temporal/temporal-opentracing "1.27.0"]]
3535
:resource-paths ["test/temporal/test/resources"]}}
3636
:cloverage {:runner :eftest
3737
:runner-opts {:multithread? false

src/temporal/client/worker.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ Options for configuring the worker-factory (See [[start]])
3838
| :max-workflow-thread-count | Maximum number of threads available for workflow execution across all workers created by the Factory. | int | 600 |
3939
| :worker-interceptors | Collection of WorkerInterceptors | [WorkerInterceptor](https://javadoc.io/doc/io.temporal/temporal-sdk/latest/io/temporal/common/interceptors/WorkerInterceptor.html) | |
4040
| :workflow-cache-size | To avoid constant replay of code the workflow objects are cached on a worker. This cache is shared by all workers created by the Factory. | int | 600 |
41+
| :using-virtual-workflow-threads | Use Virtual Threads for all workflow threads across all workers created by this factory. This option is only supported for JDK >= 21. If set then :max-workflow-thread-count is ignored. | boolean | false |
4142
"
4243

4344
{:enable-logging-in-replay #(.setEnableLoggingInReplay ^WorkerFactoryOptions$Builder %1 %2)
4445
:max-workflow-thread-count #(.setMaxWorkflowThreadCount ^WorkerFactoryOptions$Builder %1 %2)
4546
:worker-interceptors #(.setWorkerInterceptors ^WorkerFactoryOptions$Builder %1 (into-array WorkerInterceptor %2))
46-
:workflow-cache-size #(.setWorkflowCacheSize ^WorkerFactoryOptions$Builder %1 %2)})
47+
:workflow-cache-size #(.setWorkflowCacheSize ^WorkerFactoryOptions$Builder %1 %2)
48+
:using-virtual-workflow-threads #(.setUsingVirtualWorkflowThreads ^WorkerFactoryOptions$Builder %1 %2)})
4749

4850
(defn ^:no-doc worker-factory-options->
4951
^WorkerFactoryOptions [params]

test/temporal/test/vthreads.clj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; Copyright © Manetu, Inc. All rights reserved
2+
3+
(ns temporal.test.vthreads
4+
(:require [clojure.test :refer :all]
5+
[taoensso.timbre :as log]
6+
[promesa.core :as p]
7+
[promesa.exec :refer [vthreads-supported?]]
8+
[temporal.client.core :as c]
9+
[temporal.testing.env :as e]
10+
[temporal.workflow :refer [defworkflow]])
11+
(:import [java.time Duration]))
12+
13+
(def task-queue ::default)
14+
15+
(defworkflow vthread-workflow
16+
[args]
17+
(-> (Thread/currentThread)
18+
(.isVirtual)))
19+
20+
(defn execute [opts]
21+
(let [env (e/create opts)
22+
client (e/get-client env)
23+
_ (e/start env {:task-queue task-queue})
24+
workflow (c/create-workflow client vthread-workflow {:task-queue task-queue :workflow-execution-timeout (Duration/ofSeconds 1) :retry-options {:maximum-attempts 1}})]
25+
(c/start workflow {})
26+
@(-> (c/get-result workflow)
27+
(p/finally (fn [_ _]
28+
(e/stop env))))))
29+
30+
(deftest the-test
31+
(testing "Verifies that we do not use vthreads by default"
32+
(is (false? (execute {}))))
33+
(testing "Verifies that we do not use vthreads if we specifically disable them"
34+
(is (false? (execute {:worker-factory-options {:using-virtual-workflow-threads false}}))))
35+
(testing "Verifies that we can enable vthread support"
36+
(if vthreads-supported?
37+
(is (true? (execute {:worker-factory-options {:using-virtual-workflow-threads true}})))
38+
(log/info "vthreads require JDK >= 21, skipping test"))))

0 commit comments

Comments
 (0)