 
 (defn inject-batch-resources [event]
   (let [cycle-params {:onyx.core/lifecycle-id (java.util.UUID/randomUUID)}]
-    (merge event cycle-params (l-ext/inject-batch-resources* event))))
+    (merge event cycle-params ((:onyx.core/compiled-pre-batch-fn event)
+                               (l-ext/inject-batch-resources* event)))))
 
 (defn read-batch [event]
   (let [rets (p-ext/read-batch event)]

  (merge event (p-ext/write-batch event)))

(defn close-batch-resources [event]
  (merge event (l-ext/close-batch-resources* event)))

(defn launch-aux-threads!
  [messenger event outbox-ch seal-ch completion-ch task-kill-ch]

  (stop [component]
    (taoensso.timbre/info (format "[%s] Stopping Task LifeCycle for %s" id (:onyx.core/task (:pipeline-data component))))
    (when-let [event (:pipeline-data component)]
      ((:onyx.core/compiled-post-fn event) (l-ext/close-lifecycle-resources* event))

      ;; Ensure task operations are finished before closing peer connections
      (close! (:seal-ch component))
