Alternera.Plugin.Provisional.Calls (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

Provisional: added for Script, and a change to it needs a changelog line but no new major (docs/USER_PLUGINS_DESIGN.md). The namespace has nothing to do with the context's :provisional? key.

A step calling a pipeline of its tenant while it runs. start/1 gives a handle, or nil where the runner offers none (a Call or For each step, a test, a preview). call/3 runs a pipeline on the exchange as the step got it plus what earlier calls wrote, and gives a new handle. finish/2 puts the last handle on the step's extras, and the runner goes on from the exchange the calls left, with their outcomes nested under the step.

call/3 must run in the process that runs the step: a plugin that does its work in a process of its own relays the call back, as Plugins.Script.Sandbox does. A call's time is capped at time_left_ms, and a failure the step does not handle should fail the step with the type call/3 gave.

The handle is opaque.

Summary

Types

The exchange after a call: :view, the context's view; :current, the phase's message or body as the callee left it; :result, the callee's result or nil; and in a body phase :content_type.

A pipeline's id or name, with the inputs of the call.

Functions

Calls a pipeline: {{:ok, reply}, handle} or {{:error, type, message}, handle}.

extras with what the calls left, for the step's result.

A handle for the step context belongs to, or nil.

Types

handle()

@opaque handle()

reply()

@type reply() :: %{
  :view => map(),
  :current => term(),
  :result => term(),
  optional(:content_type) => String.t() | nil
}

The exchange after a call: :view, the context's view; :current, the phase's message or body as the callee left it; :result, the callee's result or nil; and in a body phase :content_type.

target()

@type target() :: {String.t(), map()}

A pipeline's id or name, with the inputs of the call.

Functions

call(handle, target, time_left_ms)

@spec call(handle(), target(), non_neg_integer()) ::
  {{:ok, reply()} | {:error, String.t(), String.t()}, handle()}

Calls a pipeline: {{:ok, reply}, handle} or {{:error, type, message}, handle}.

finish(extras, map)

@spec finish(map(), handle()) :: map()

extras with what the calls left, for the step's result.

start(arg1)

@spec start(map()) :: handle() | nil

A handle for the step context belongs to, or nil.