-
Notifications
You must be signed in to change notification settings - Fork 23
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
Use pipes to stream logs #52
base: master
Are you sure you want to change the base?
Conversation
I am not sure about the choice of streaming library. I know about |
cee9c9c
to
776d5ea
Compare
..instead of collecting them in memory and then returning everything at once. I did this by changing the `MonadStore` to: ```haskell type MonadStore a = ExceptT Error (Producer Logger (ReaderT Socket IO)) a ``` It's a `Producer` of log messages that can fail with an `Error`: ```haskell data Error = LogError Int LBS.ByteString | ParseError String | ConnError String ``` `runStore` can now accept a `Consumer Logger IO (Either Error a)` parameter to consume logs incrementally. I added a `runStore_` that simply discards all logs. Similarly, I changed the `runOpArgs` and `runOp`: now they accept a `Get a` parser that is used to get the result. `runOp_` and `runOpArgs_` assume that op does not return anything interesting.
I was hoping to use the `StorePath` type from `System.Nix.StorePath`, but I am not sure how to construct its values at runtime. I ended up giving `buildPaths` a simpler type that expects a list of bytestrings.
776d5ea
to
23a100c
Compare
This is nice! Personally I like pipes. Will try to integrate these changes when prerequisites are in place. |
Thanks! |
Soon? :D |
It's not quite clear if pipes or dlist from anoher PR or streaming lib.. which is why I've started exploring effect systems so you could possibly use any of that by just replacing interpreter. |
For a simple solution that doesn't require adding any extra dependencies, why not just use an IO callback? I.e., plumb a function with signature Then the user can specify this callback and do whatever they like with it, such as feed it into a streaming library. (I assume this is possible with |
Soon^tm! 🙃 |
This was obvious to me but there were many more things that need handling first, but it is done now and you can implement your own runner that uses a custom If anyone knows a good solution how to make it easier to implement please step forward! (or even better submit a PR 😺 ) I will try to implement another runner that prints log to stdout soon^tm just to see how bad it is because the default one is only useful for testing. |
..instead of collecting them in memory and then returning everything at once.
I did this by changing the
MonadStore
to:It's a
Producer
of log messages that can fail with anError
:runStore
can now accept aConsumer Logger IO (Either Error a)
parameter to consume logs incrementally. I also added arunStore_
that simply discards all logs.Similarly, I changed the
runOpArgs
andrunOp
: now they accept aGet a
parser that is used to get the result.runOp_
andrunOpArgs_
assume that op does not return anything interesting.I also implemented the
buildPaths
op to confirm that this works.