pocketenv/services

Manage long-running services inside a sandbox.

A service is a named process (e.g. a web server or background worker) that the platform can start, stop, and restart independently.

Types

A service running (or registered to run) inside a sandbox.

pub type Service {
  Service(
    id: String,
    name: String,
    command: String,
    ports: option.Option(List(Int)),
    description: option.Option(String),
    status: String,
    created_at: String,
  )
}

Constructors

  • Service(
      id: String,
      name: String,
      command: String,
      ports: option.Option(List(Int)),
      description: option.Option(String),
      status: String,
      created_at: String,
    )

Values

pub fn create(
  sb: sandbox.ConnectedSandbox,
  name: String,
  command: String,
  ports: option.Option(List(Int)),
  description: option.Option(String),
) -> Result(Nil, pocketenv.PocketenvError)

Registers a new service in the sandbox.

  • name — unique name for the service
  • command — shell command to run
  • ports — optional list of ports the service listens on
  • description — optional human-readable description

Example

let assert Ok(Nil) =
  sb |> services.create("api", "node server.js", Some([3000]), None)
pub fn delete(
  sb: sandbox.ConnectedSandbox,
  service_id: String,
) -> Result(Nil, pocketenv.PocketenvError)

Deletes the service identified by service_id.

pub fn list(
  sb: sandbox.ConnectedSandbox,
) -> Result(List(Service), pocketenv.PocketenvError)

Lists all services registered in the sandbox.

Example

let assert Ok(svcs) = sb |> services.list()
pub fn restart(
  sb: sandbox.ConnectedSandbox,
  service_id: String,
) -> Result(Nil, pocketenv.PocketenvError)

Restarts the service identified by service_id.

pub fn service_decoder() -> decode.Decoder(Service)

JSON decoder for Service.

pub fn start(
  sb: sandbox.ConnectedSandbox,
  service_id: String,
) -> Result(Nil, pocketenv.PocketenvError)

Starts the service identified by service_id.

pub fn stop(
  sb: sandbox.ConnectedSandbox,
  service_id: String,
) -> Result(Nil, pocketenv.PocketenvError)

Stops the service identified by service_id.

Search Document