|
| 1 | +;; Copyright © Manetu, Inc. All rights reserved |
| 2 | + |
| 3 | +(ns temporal.test.slingshot |
| 4 | + (:require [clojure.test :refer :all] |
| 5 | + [taoensso.timbre :as log] |
| 6 | + [slingshot.slingshot :refer [try+ throw+]] |
| 7 | + [temporal.client.core :as c] |
| 8 | + [temporal.workflow :refer [defworkflow]] |
| 9 | + [temporal.activity :refer [defactivity] :as a] |
| 10 | + [temporal.exceptions :as e] |
| 11 | + [temporal.test.utils :as t])) |
| 12 | + |
| 13 | +(use-fixtures :once t/wrap-service) |
| 14 | + |
| 15 | +(defactivity slingshot-nonretriable-activity |
| 16 | + [ctx {:keys [name] :as args}] |
| 17 | + (log/info "slingshot-nonretriable-activity:" args) |
| 18 | + (throw+ {:type ::test1 ::e/non-retriable? true})) |
| 19 | + |
| 20 | +(defactivity slingshot-retriable-activity |
| 21 | + [ctx {:keys [name] :as args}] |
| 22 | + (log/info "slingshot-retriable-activity:" args) |
| 23 | + (throw+ {:type ::test2})) |
| 24 | + |
| 25 | +(defworkflow slingshot-workflow |
| 26 | + [args] |
| 27 | + (log/info "slingshot-workflow:" args) |
| 28 | + (try+ |
| 29 | + @(a/invoke slingshot-nonretriable-activity args) |
| 30 | + (catch [:type ::test1] _ |
| 31 | + (log/info "caught stone 1") |
| 32 | + (try+ |
| 33 | + @(a/invoke slingshot-retriable-activity args) |
| 34 | + (catch [:type ::test2] _ |
| 35 | + (log/info "caught stone 2") |
| 36 | + (throw+ {:type ::test3})))))) |
| 37 | + |
| 38 | +(deftest the-test |
| 39 | + (testing "Verifies that we can catch slingshot stones across activity/workflow boundaries" |
| 40 | + (let [workflow (t/create-workflow slingshot-workflow)] |
| 41 | + (c/start workflow {}) |
| 42 | + (try+ |
| 43 | + @(c/get-result workflow) |
| 44 | + (throw (ex-info "should not get here" {})) |
| 45 | + (catch [:type ::test3] _ |
| 46 | + (log/info "caught stone 3")))))) |
0 commit comments