View Source Consul.Connection (consulex v0.2.1)

Handle Tesla connections for Consul.

Link to this section Summary

Functions

Builds a base URL based on a given server spec.

Converts a Consul.Request struct into a keyword list to send via Tesla.

Execute a request on this connection

Builds a Tesla client.

Link to this section Types

Link to this section Functions

Builds a base URL based on a given server spec.

Specs

build_request(Consul.Request.t()) :: keyword()

Converts a Consul.Request struct into a keyword list to send via Tesla.

Link to this function

execute(connection, request)

View Source

Specs

execute(Tesla.Client.t(), Consul.Request.t()) :: {:ok, Tesla.Env.t()}

Execute a request on this connection

returns

Returns

  • {:ok, Tesla.Env.t} - If the call was successful
  • {:error, reason} - If the call failed
Link to this function

new(base_url, opts \\ [])

View Source

Builds a Tesla client.

options

Options

  • adapter - specify custom Tesla adapter, if not set will use Tesla's default one
  • retry - options for Tesla.Middleware.Retry middleware
  • timeout - when given, will include Tesla.Middleware.Timeout middleware configured with given value
  • token - when given, will include x-consul-token header with given value in the requests
  • wait - when given, will include Tesla.Middleware.ConsulWatch middleware configured with given value in milliseconds

When using wait option, make sure its value is larger than the timeout used by the underlying adapter (specified in options or default one). Otherwise, the request may be timing out before wait period passes.

Note that using timeout option is not always sufficient to achieve this as some adapters (e.g. Tesla.Adapter.Finch) are not compatible with Tesla.Middleware.Timeout middleware that is used when timeout option is specified.