               [onyx.state.state-extensions :as state-extensions]
               [onyx.static.default-vals :refer [defaults arg-or-default]]))
 
-(defn call-with-lifecycle-handler [event phase handler-fn f & args]
-  (try
-    (apply f args)
-    (catch Throwable t
-      (let [action (handler-fn event phase t)]
-        (cond (= action :kill)
-              (throw t)
-              
-              (= action :restart)
-              (do (>!! (:onyx.core/restart-ch event) true)
-                  (throw t))
-              
-              :else
-              (throw (ex-info
-                      (format "Internal error, cannot handle exception with policy %s, must be one of #{:kill :restart :defer}"
-                              action)
-                      {})))))))
-
 (defn windowed-task? [event]
   (or (not-empty (:onyx.core/windows event))
       (not-empty (:onyx.core/triggers event))))


                   (= ch retry-ch)
                   (->> (p-ext/retry-segment pipeline event v)
                        (call-with-lifecycle-handler
                          event
                          :lifecycle/after-retry-segment
                          (:onyx.core/compiled-handle-exception-fn event)
                          compiled-after-retry-segment-fn
                          event
                          v))

                   (= ch seal-ch)
                   (do

    rets))

(defn close-batch-resources [event]
  (let [rets (lc/invoke-after-batch event)]
    (taoensso.timbre/trace (format "[%s / %s] Closed batch plugin resources"
                                   (:onyx.core/id rets)
                                   (:onyx.core/lifecycle-id rets)))
