Execution of the virtual call stack inside a transaction

20 views
Skip to first unread message

matus...@gmail.com

unread,
Sep 11, 2019, 8:50:26 AM9/11/19
to pedestal-users
Hi everybody

Let's say I have a ring middleware ("wrap-in-transaction") which wraps the whole middleware chain in a transaction and rolls back if any of the wrapped middlewares raises an exception.

(defn main-handler []
  (-> handler
       middleware1
       ...
       middlewareN
       wrap-in-transaction))

How does one do it in Pedestal? 

Basically what I imagine is having an interceptor (or more) which somehow wraps all the further call queue inside a transaction and on ":leave" would rollback if ":errors".

But how?

Thanks
Matus

matus...@gmail.com

unread,
Sep 11, 2019, 8:53:50 AM9/11/19
to pedestal-users
One thing more:

I am using https://clojure.github.io/java.jdbc/#clojure.java.jdbc/db-transaction* for that matter which expects a single function as the second argument (that's why it works so nicely in the Ring middleware function wrapping scenario).

Linus Ericsson

unread,
Sep 11, 2019, 9:26:41 AM9/11/19
to matus...@gmail.com, pedestal-users
I have to admit I have never used the jdbc-libraries with clojure, but looking into the source code, it looks like a not very good match for pedestal as is.

In pedestal I would expect something along the lines:

1. in a transaction-interceptor:
on enter: do the necessary things to enter a transaction and add the transaction object on the context in some namespaced key.
on leave: if there is a transaction in the context do the necessary things to leave the transaction. Remove the transaction object from the context since were done with it.
on error: (before or after the transaction interceptor) - cancel the transaction and remove the transaction object.

(the error interceptor could be either in the transactor interceptor, or as a separate interceptor)

When I look into the source code of java.jdbc and jdbc.next it is not apparent how to create a transaction and then with something else leave it.

/Linus



--
You received this message because you are subscribed to the Google Groups "pedestal-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pedestal-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pedestal-users/c21f1598-4a9a-49f4-8afd-b1350d5fb80e%40googlegroups.com.

Daniel De Aguiar

unread,
Sep 13, 2019, 11:02:03 AM9/13/19
to pedestal-users
I don't see how it's possible either. I suggest keep transaction processing within a single interceptor and use upstream interceptors for data preparation and downstream interceptors for response shaping. My preference is to keep endpoint responsibilities small and focused.

/dan
To unsubscribe from this group and stop receiving emails from it, send an email to pedesta...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages