-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cats-Effect intergation (WIP) #89
base: master
Are you sure you want to change the base?
Cats-Effect intergation (WIP) #89
Conversation
...cats-effect/src/test/scala/com/augustnagro/magnum/magcats/ImmutableRepoCatsEffectTests.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/cats-effect.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/cats-effect.scala
Outdated
Show resolved
Hide resolved
Thanks for opening this MR @KaranAhlawat ! We just merged some important changes to the ZIO module: #85 I suggest looking at package
|
Hey, thanks, I'll take the changes into account and push some commits |
3b248a1
to
8c28a68
Compare
Is it fine if I pull in |
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Show resolved
Hide resolved
Okay something might be seriously wrong with the implementation, I'm not entirely sure yet. Please hold off on merging it till I can figure this bug(?) out. Context: I was using a locally published version to test the API, see how it feels. But for some reason, after a couple runs of the main method, HikariCP throws an exception saying Edit: The resource cleanup is working fine, I think it was some other JVM process going Haywire (possibly IntelliJ DB tools) |
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
Outdated
Show resolved
Hide resolved
Yes, absolutely. |
cn.setAutoCommit(false) | ||
} >> | ||
Sync[F] | ||
.interruptible(f(using DbTx(cn, sqlLogger))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see any downside of transact being interruptible @guizmaii ?
I can see the benefit if the user has a request timeout that triggers during a long-running transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any downside. That's even something I might want to backport to the ZIO module 🤔
Note that this interruption is quite brutal: the only way for Cats to interrupt the f
call is to call Thread.interrupt
, which will stop the thread running the code.
Could this be an issue? 🤔
I don't think so 🤔
In transactor and apply methods
0361313
to
3bd740e
Compare
Yeah I'd like to see a test where we try to cancel a long running query and
see if it actually works.
…On Sun, Jan 26, 2025, 12:47 AM Jules Ivanic ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
magnum-cats-effect/src/main/scala/com/augustnagro/magnum/magcats/Transactor.scala
<#89 (comment)>:
> + )
+
+ def connect[A](f: DbCon ?=> A): F[A] =
+ useRateLimitedConnection: cn =>
+ Sync[F].delay(connectionConfig(cn)) >>
+ Sync[F].interruptible(f(using DbCon(cn, sqlLogger)))
+
+ def transact[A](f: DbTx ?=> A): F[A] =
+ useRateLimitedConnection: cn =>
+ Sync[F]
+ .delay {
+ connectionConfig(cn)
+ cn.setAutoCommit(false)
+ } >>
+ Sync[F]
+ .interruptible(f(using DbTx(cn, sqlLogger)))
I don't see any downside. That's even something I might want to backport
to the ZIO module 🤔
Note that this interruption is quite brutal: the only way for Cats to
interrupt the f call is to call Thread.interrupt, which will stop the
thread running the code.
Could this be an issue? 🤔
I don't think so 🤔
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQOKNWD7UYAYS6Y4YB2BK32MSOLPAVCNFSM6AAAAABVE67IU2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDKNZUGE3TGOJWGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I guess we can add a test for a |
I'd be happy to contribute, but it will be a few days. Like you said we can have a fiber run a query with a long pg_sleep(). Then we interrupt the fiber and make sure that it actually gets cancelled. My guess is that, since Thread.interrupt just sets a flag, we will need to follow Doobie's example: typelevel/doobie#699 |
The PR is in draft, mostly because I'm not sure about
Trace
implicit is needed by Magnum, and if so, which library should be included in the module.The tests for now are just the ZIO suite copied over and modified to run with Cats-Effect, and are all passing currently. Tested on Podman.
Please let me know any comments, concerns, advice etc etc you may have!