File tree Expand file tree Collapse file tree 5 files changed +63
-7
lines changed Expand file tree Collapse file tree 5 files changed +63
-7
lines changed Original file line number Diff line number Diff line change 50
50
```"
51
51
[^ScheduleClient client schedule-id options]
52
52
(let [schedule (s/schedule-> options)
53
- schedule-options (s/schedule-options-> options)]
53
+ schedule-options (s/schedule-options-> ( :schedule options) )]
54
54
(log/tracef " create schedule:" schedule-id)
55
55
(.createSchedule client schedule-id schedule schedule-options)))
56
56
Original file line number Diff line number Diff line change 1
1
; ; Copyright © Manetu, Inc. All rights reserved
2
2
3
3
(ns ^:no-doc temporal.internal.promise
4
- (:require [taoensso.timbre :as log]
5
- [promesa.protocols :as pt]
4
+ (:require [promesa.protocols :as pt]
6
5
[temporal.internal.utils :refer [->Func] :as u])
7
6
(:import [clojure.lang IDeref IBlockingDeref]
8
7
[io.temporal.workflow Promise]
Original file line number Diff line number Diff line change 1
1
(ns ^:no-doc temporal.internal.schedule
2
- (:require [clojure.walk :refer [stringify-keys]]
3
- [temporal.internal.utils :as u]
2
+ (:require [temporal.internal.utils :as u]
4
3
[temporal.internal.workflow :as w])
5
4
(:import [io.temporal.api.enums.v1 ScheduleOverlapPolicy]
6
5
[io.temporal.client.schedules
Original file line number Diff line number Diff line change @@ -30,6 +30,31 @@ promises returned from [[temporal.activity/invoke]] from within workflow context
30
30
(p/then (fn [_]
31
31
(mapv deref coll)))))
32
32
33
+ (defn allSettled
34
+ " Returns Promise that becomes completed when all arguments are completed, even in the face of errors.
35
+
36
+ *N.B. You must handle the exceptions in the returned promises when done*
37
+
38
+ Similar to [promesa/all](https://funcool.github.io/promesa/latest/promesa.core.html#var-all) but designed to work with
39
+ promises returned from [[temporal.activity/invoke]] from within workflow context.
40
+
41
+ For more Java SDK samples example look here:
42
+ https://github.com/temporalio/samples-java/tree/main/core/src/main/java/io/temporal/samples/batch
43
+
44
+ ```clojure
45
+ (-> (allSettled [(a/invoke activity-a ..) (a/invoke activity-b ..)])
46
+ (promesa.core/then (fn [[a-result b-result]] ...)))
47
+ ```
48
+ "
49
+ [coll]
50
+ (letfn [(wait! [^Promise p] (try (.get p) (catch Exception _)))]
51
+ (-> (into-array Promise (mapv wait! (->array coll)))
52
+ (Promise/allOf )
53
+ (pt/->PromiseAdapter )
54
+ ; ; The promises are all completed at this point,
55
+ ; ; this is just to use the promesa library
56
+ (p/then (fn [_] (mapv deref coll))))))
57
+
33
58
(defn race
34
59
" Returns Promise that becomes completed when any of the arguments are completed.
35
60
@@ -54,4 +79,4 @@ promises returned from [[temporal.activity/invoke]] from within workflow context
54
79
(defn rejected
55
80
" Returns a new, rejected promise"
56
81
[^Exception e]
57
- (Workflow/newFailedPromise e))
82
+ (Workflow/newFailedPromise e))
Original file line number Diff line number Diff line change 32
32
(testing " Verifies that we can launch activities in parallel"
33
33
(let [workflow (t/create-workflow concurrency-workflow)]
34
34
(c/start workflow {})
35
- (is (-> workflow c/get-result deref count (= 10 ))))))
35
+ (is (-> workflow c/get-result deref count (= 10 ))))))
36
+
37
+ (defactivity all-settled-activity
38
+ [ctx args] args )
39
+
40
+ (defworkflow all-settled-workflow
41
+ [args]
42
+ @(-> (pt/all (map #(a/invoke all-settled-activity %) (range 10 )))
43
+ (p/then (fn [r] r))
44
+ (p/catch (fn [e] (:args (ex-data e))))))
45
+
46
+ (defactivity error-prone-activity
47
+ [ctx args]
48
+ (when (= args 5 )
49
+ (throw (ex-info " error on 5" {:args args})))
50
+ args )
51
+
52
+ (defworkflow error-prone-workflow
53
+ [args]
54
+ @(-> (pt/all (map #(a/invoke error-prone-activity %) (range 10 )))
55
+ (p/then (fn [r] r))
56
+ (p/catch (fn [e] (:args (ex-data e))))))
57
+
58
+ (deftest test-all-settled
59
+ (testing " Testing that allSettled waits for all the activities to complete
60
+ just like `p/all` does in spite of errors"
61
+ (let [workflow (t/create-workflow all-settled-workflow)]
62
+ (c/start workflow {})
63
+ (is (-> workflow c/get-result deref count (= 10 )))))
64
+ (testing " Testing that allSettled waits for all the activities to complete
65
+ despite error and can return the errors"
66
+ (let [workflow (t/create-workflow error-prone-workflow)]
67
+ (c/start workflow {})
68
+ (is (-> workflow c/get-result deref (= 5 ))))))
You can’t perform that action at this time.
0 commit comments