Condukt.Sandbox.Lazy (Condukt v3.0.0)

Copy Markdown View Source

A sandbox that starts another on first use and lets it go when idle, for a second machine a session needs now and then, such as a Mac beside a Linux one.

{:ok, mac} =
  Condukt.Sandbox.new(Condukt.Sandbox.Lazy,
    sandbox: {MyApp.MacSandbox, image: "macos-15"},
    idle_after: :timer.minutes(10),
    before_use: fn mac -> Condukt.Sandbox.Sync.mirror(linux, ".", mac, "work/repo") end
  )

tools: [
  Condukt.Tools.Bash,
  {Condukt.Tools.Bash, name: "MacBash", sandbox: mac},
  {Condukt.Tools.Read, name: "MacRead", sandbox: mac}
]

A tool given sandbox: runs against it instead of the session's (see the Sandbox guide). Options:

  • :sandbox — the sandbox to start, as the session's :sandbox takes it
  • :idle_after — milliseconds without a call after which it is let go (default ten minutes): Condukt.Sandbox.activity/2 with :idle when it takes activity, as a Tuist sandbox pauses on it, else Condukt.Sandbox.shutdown/1, and it starts again on the next call
  • :before_use — a function of the sandbox run before a call that starts work or touches files reaches it (an exec, a process start, a file read, write, edit, glob, or grep), at most once a second, such as a one-way sync of the worktree. It runs in the process that keeps the machine, so calls that arrive while it runs wait for it, and two never run at once. Reading, writing to, stopping, or watching a running process does not run it, so a parked command's watcher never syncs under the running command.
  • :owner — the process the machine lives no longer than: when it exits, the machine is let go for good, so an owner that dies without Condukt.Sandbox.shutdown/1 does not leave it running. Defaults to the process that calls Condukt.Sandbox.new/2. Pass a process that outlives the sessions using it, such as the one that starts them, when that is not the caller, or nil to keep it until Condukt.Sandbox.shutdown/1.

A parked command keeps it in use, since its watcher reads it every few seconds.

Summary

Functions

The started sandbox, starting it when needed.

Functions

sandbox(sandbox)

The started sandbox, starting it when needed.