Skip to content

Commit

Permalink
Gracefully handle eviction exceptions rather than throw an ugly ERROR…
Browse files Browse the repository at this point in the history
… report

Signed-off-by: Greg Haskins <[email protected]>
  • Loading branch information
ghaskins committed Mar 18, 2024
1 parent 1d19132 commit 17df2ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
:cloverage {:runner :eftest
:runner-opts {:multithread? false
:fail-fast? true}
:fail-threshold 90
:fail-threshold 89
:ns-exclude-regex [#"temporal.client.worker"]})
4 changes: 4 additions & 0 deletions src/temporal/internal/activity.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[temporal.internal.exceptions :as e]
[temporal.common :as common])
(:import [java.time Duration]
[io.temporal.internal.sync DestroyWorkflowThreadError]
[io.temporal.activity Activity ActivityInfo DynamicActivity ActivityCancellationType]
[io.temporal.activity ActivityOptions ActivityOptions$Builder LocalActivityOptions LocalActivityOptions$Builder]
[clojure.core.async.impl.channels ManyToManyChannel]))
Expand Down Expand Up @@ -107,6 +108,9 @@
(log/trace activity-id "calling" f "with args:" a)
(try+
(result-> activity-id (f ctx a))
(catch DestroyWorkflowThreadError ex
(log/debug activity-id "thread evicted")
(throw ex))
(catch Object o
(log/error &throw-context)
(e/forward &throw-context)))))
Expand Down
32 changes: 18 additions & 14 deletions src/temporal/internal/workflow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[temporal.internal.utils :as u])
(:import [io.temporal.api.enums.v1 WorkflowIdReusePolicy]
[io.temporal.client WorkflowOptions WorkflowOptions$Builder]
[io.temporal.internal.sync DestroyWorkflowThreadError]
[io.temporal.workflow Workflow WorkflowInfo]))

(extend-protocol p/Datafiable
Expand Down Expand Up @@ -75,17 +76,20 @@

(defn execute
[ctx dispatch args]
(try+
(let [{:keys [workflow-type workflow-id]} (get-info)
d (u/find-dispatch dispatch workflow-type)
f (:fn d)
a (u/->args args)
_ (log/trace workflow-id "calling" f "with args:" a)
r (if (-> d :type (= :legacy))
(f ctx {:args a :signals (s/create-signal-chan)})
(f a))]
(log/trace workflow-id "result:" r)
(nippy/freeze r))
(catch Object o
(log/error &throw-context)
(e/forward &throw-context))))
(let [{:keys [workflow-type workflow-id]} (get-info)]
(try+
(let [d (u/find-dispatch dispatch workflow-type)
f (:fn d)
a (u/->args args)
_ (log/trace workflow-id "calling" f "with args:" a)
r (if (-> d :type (= :legacy))
(f ctx {:args a :signals (s/create-signal-chan)})
(f a))]
(log/trace workflow-id "result:" r)
(nippy/freeze r))
(catch DestroyWorkflowThreadError ex
(log/debug workflow-id "thread evicted")
(throw ex))
(catch Object o
(log/error &throw-context)
(e/forward &throw-context)))))

0 comments on commit 17df2ee

Please sign in to comment.