Juggernaut.Server.Client (Juggernaut v0.4.0)

Copy Markdown View Source

The client side of mix juggernaut.server (design notes §12): finds the server of a checkout from server/server.json and server/token, sends one request and relays the frames that come back.

attach/3 is what mix juggernaut and mix juggernaut.check do when a server is reachable: the job's stdout goes through the Mix shell, its stderr to stderr (or ctx.progress), the queue position to stderr, and its exit code is returned. An address file whose server no longer answers is treated as no server.

Summary

Types

Where a server listens.

Functions

The address of root's server, or :none when no address file is readable.

Runs kind (run or check) with argv on the server of ctx.root: {:attached, code} with the job's exit code, or :none when no server answers.

Shows one reply frame of a job: its output, its queue position or a refusal.

Sends kind (run, check, status, stop) with fields to root's server and calls on_frame with each reply frame until the last. Returns {:ok, last_frame}, :none when no server answers, or an infrastructure error when the connection drops.

Types

address()

@type address() :: %{port: :inet.port_number(), token: String.t()}

Where a server listens.

Functions

address(root)

@spec address(Path.t()) :: {:ok, address()} | :none

The address of root's server, or :none when no address file is readable.

attach(kind, argv, ctx)

@spec attach(String.t(), [String.t()], map()) :: {:attached, 0..3} | :none

Runs kind (run or check) with argv on the server of ctx.root: {:attached, code} with the job's exit code, or :none when no server answers.

print(arg1, ctx)

@spec print(map(), map()) :: :ok

Shows one reply frame of a job: its output, its queue position or a refusal.

request(root, kind, fields, on_frame \\ fn _frame -> :ok end)

@spec request(Path.t(), String.t(), map(), (map() -> term())) ::
  {:ok, map()} | :none | {:error, Juggernaut.Error.t()}

Sends kind (run, check, status, stop) with fields to root's server and calls on_frame with each reply frame until the last. Returns {:ok, last_frame}, :none when no server answers, or an infrastructure error when the connection drops.