Coder Social home page Coder Social logo

cradle's People

Contributors

eviefp avatar jkarni avatar r-vdp avatar soenkehahn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

r-vdp eviefp

cradle's Issues

Streaming, handles, and async

We briefly discussed this already, but I thought I'd bring up the related set of issues that are streaming, returning handles rather than files, and async execution of processes.

One option that we came up with is passing the consumer as an argument. But there are a couple more:

  • Having a separate AsyncOutput class. Instead of instances for Exit and Stdout, for example, it might have instances for Async Exit and StdoutHandle. It would, I imagine, be called with a different function that run (e.g., start).
  • Having Output instances for Async Exit, StdoutHandle etc, but expanding the class so extractOutput has a signature of Either ProcessStarted ProcessResult -> output instead of just ProcessResult -> output. If any output is async, then we get a Left. This likely isn't safe, in the sense that having e.g. (ExitCode, StdoutHandle) might just be an error.
  • Fancy types to make sure sync and async outputs aren't mixed. I feel like this might get messy, but it might also help with other non-sensical combinations (like having two different types of Stdout).

It's probably sensible to just put on all these questions, but I was thinking a bit about this and wanted to just jot down ideas.

Handles, encoding, and binary mode

Currently the output Outputs (StdoutTrimmed, StdoutUntrimmed, Stderr) return bytestrings. The idea then is that users will call conversion functions themselves.

There are, I think, several problems with this:

  • Does it even make sense to talk about "newline" and trimming on binary inputs?
  • I believe generally the handles are not set to binary mode (e.g., try doing hGetEncoding)
  • Users can't get access to the encoding of the relevant handles, so they don't have an easy way to decide what the encoding even should be
  • In general, deciding whether output is binary or not (and what the encoding is) isn't, I think, something to be done after the fact at all, since those are properties of the handle.

What I propose instead is:

  • The bytestring function calls hSetBinaryMode True on the handle
  • There is only one bytestring function for each output handle, and it does no trimming
  • There's a Std(out/err)Text, with trimmed and untrimmed variants. This behaves like the functions in Data.Text.IO; that is, it uses the locale encoding and converts from that (potentially just directly using the Data.Text.IO functions
  • Optionally, there are functions like StdoutUtf8 and StdoutLatin1 (with trimmed variants?), which set the encoding of the handle to the respective encoding, and use the corresponding encoding/decoding functions in Data.Text.

Expose everything

I tried using cradle to write a helper for limiting system resources with systemd, but ran into the problem that only the Cradle module is exposed, and that doesn't expose the Input class method, or the ProcessConfig type. I think those should be re-exported from somewhere. But more importantly, maybe all modules should be exposed, even if with an Internal name? Otherwise anyone who has an unforeseen use case has to fork the library.

Design of inputs

As I mentioned in another issue, I was hoping to write a SystemdRunLimits Input, and a couple of questions came up:

    1. Why is Input a class? All of the inputs are just representing ProcessConfiguration -> ProcessConfiguration functions. So they could just be combined via <> rather than anything fancier. E.g.:
run (cmd "mycmd" <> args ["arg1", "arg2"] <> stdinHandle hdl <> workingDir "some-dir")

Type inference would improve, the codebase would be simpler, and the types much easier to read.

    1. Why is the command (and, I would think, also the arguments) not a "proper" argument to run (instead of an Input)? The disadvantages are that a clearly wrong use of run typechecks but throws a runtime error, and that other Inputs that may want to modify the command (e.g.: a Sudo Input), now have to be run in a very specific order which is opaque to the user (and, to me at least, it's harder to read or understand what each command is doing).

(Combined with 2 the above example would be:

run "mycmd" ["arg1", "arg2"] (stdinHandle hdl <> workingDir "some-dir")

And run :: (MonadIO m, Output a) => String -> [String] -> (ProcessConfig -> ProcessConfig) -> m a (though having a newtype for ProcessConfig -> ProcessConfig might be nice).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.