Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

KaranAhlawat
Copy link

@KaranAhlawat KaranAhlawat commented Jan 14, 2025

The PR is in draft, mostly because I'm not sure about

  1. If the typeclasses I used in the TF style are correct (I think they should be, but it's better to be 100%)
  2. If a 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!

@AugustNagro
Copy link
Owner

Thanks for opening this MR @KaranAhlawat !

We just merged some important changes to the ZIO module: #85

I suggest looking at package com.augustnagro.magnum.magzio on the master branch and following the new structure (unless you want something else of course). The big changes are:

  1. connect and transact are defined directly on Transactor. For the cats module you may want to add the IO type to Transactor like class Transactor[F: Sync](..). That's how doobie does it and should resolve @BalmungSan 's comment.
  2. Removes test dependency on magnum module by copying over the sql resource file we care about.
  3. Adds an 'exports' file, that exports some common core magnum types (can copy this from zio module)

@KaranAhlawat
Copy link
Author

Hey, thanks, I'll take the changes into account and push some commits

@KaranAhlawat KaranAhlawat force-pushed the cats-effect-integration branch from 3b248a1 to 8c28a68 Compare January 15, 2025 17:41
@KaranAhlawat
Copy link
Author

Is it fine if I pull in munit-cats-effect as a testing dependency?

@KaranAhlawat KaranAhlawat marked this pull request as ready for review January 18, 2025 16:31
@KaranAhlawat
Copy link
Author

KaranAhlawat commented Jan 18, 2025

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 Too many clients already, so I think I borked up the resource cleanup somehow somewhere. Or maybe it's something wrong with my HikariCP configuration, but who knows 😄

Edit: The resource cleanup is working fine, I think it was some other JVM process going Haywire (possibly IntelliJ DB tools)

@AugustNagro
Copy link
Owner

Is it fine if I pull in munit-cats-effect as a testing dependency?

Yes, absolutely.

cn.setAutoCommit(false)
} >>
Sync[F]
.interruptible(f(using DbTx(cn, sqlLogger)))
Copy link
Owner

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.

Copy link
Contributor

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 🤔

@KaranAhlawat KaranAhlawat force-pushed the cats-effect-integration branch from 0361313 to 3bd740e Compare January 23, 2025 13:22
@AugustNagro
Copy link
Owner

AugustNagro commented Jan 26, 2025 via email

@KaranAhlawat
Copy link
Author

I guess we can add a test for a pg_sleep cancellation, but I'm honestly not sure what that would look like.

@AugustNagro
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants