JetPluginSDK.TenantMan behaviour (JetPluginSDK v0.1.3)

The JetPluginSDK.TenantMan module provides a behaviour for implementing a tenant management supervisor.

Example

defmodule MyTenant do
  @moduledoc false

  use JetPluginSDK.TenantMan

  @spec ping(GenServer.server()) :: :pong
  def ping(server) do
    GenServer.call(server, :ping)
  end

  @impl JetPluginSDK.TenantMan
  def handle_install(_tenant) do
    {:ok, %{}}
  end

  @impl JetPluginSDK.TenantMan
  def handle_run({_tenant, tenant_state}) do
    {:ok, tenant_state}
  end

  @impl JetPluginSDK.TenantMan
  def handle_call(:ping, _from, state) do
    {:reply, :pong, state}
  end
end

Usage

children = [
  MyTenant
]

Supervisor.start_link(children, strategy: :one_for_all)

Summary

Life-cycle callbacks

Link to this callback

handle_install(tenant)

@callback handle_install(tenant()) ::
  {:ok, tenant_state()} | {:async, async()} | {:error, reason :: term()}
@callback handle_run({tenant(), tenant_state()}) ::
  {:ok, tenant_state()}
  | {:ok, tenant_state(), extra()}
  | {:error, reason :: term(), tenant_state()}
  | {:error, reason :: term(), tenant_state(), extra()}
Link to this callback

handle_uninstall({})

(optional)
@callback handle_uninstall({tenant(), tenant_state()}) ::
  {:ok, tenant_state()}
  | {:ok, tenant_state(), extra()}
  | {:async, async()}
  | {:async, async(), extra()}
  | {:error, reason :: term()}
  | {:error, reason :: term(), extra()}
Link to this callback

handle_update({}, {})

(optional)
@callback handle_update(
  {tenant_config(), tenant_capabilities()},
  {tenant(), tenant_state()}
) ::
  {:ok, tenant_state()}
  | {:ok, tenant_state(), extra()}
  | {:async, async()}
  | {:async, async(), extra()}
  | {:error, reason :: term()}
  | {:error, reason :: term(), extra()}

GenServer callbacks

Link to this callback

handle_call(request, from, {})

(optional)
@callback handle_call(
  request :: term(),
  from :: GenServer.from(),
  {tenant(), tenant_state()}
) ::
  {:reply, reply, tenant_state()}
  | {:reply, reply, tenant_state(), extra()}
  | {:noreply, tenant_state()}
  | {:noreply, tenant_state(), extra()}
  | {:stop, reason, reply, tenant_state()}
  | {:stop, reason, tenant_state()}
when reason: term(), reply: var
Link to this callback

handle_cast(request, {})

(optional)
@callback handle_cast(
  request :: term(),
  {tenant(), tenant_state()}
) ::
  {:noreply, tenant_state()}
  | {:noreply, tenant_state(), extra()}
  | {:stop, reason :: term(), tenant_state()}
Link to this callback

handle_continue(continue_arg, {})

(optional)
@callback handle_continue(
  continue_arg :: term(),
  {tenant(), tenant_state()}
) ::
  {:noreply, tenant_state()}
  | {:noreply, tenant_state(), extra()}
  | {:stop, reason :: term(), tenant_state()}
Link to this callback

handle_info(msg, {})

(optional)
@callback handle_info(
  msg :: :timeout | term(),
  {tenant(), tenant_state()}
) ::
  {:noreply, tenant_state()}
  | {:noreply, tenant_state(), extra()}
  | {:stop, reason :: term(), tenant_state()}
Link to this callback

terminate(reason, {})

(optional)
@callback terminate(
  reason,
  {tenant(), tenant_state()}
) :: term()
when reason: :normal | :shutdown | {:shutdown, term()} | term()

Types

Link to this type

tenant_module()

@type tenant_module() :: module()

Functions

Link to this function

fetch_tenant(tenant_module, tenant_id)

@spec fetch_tenant(tenant_module(), tenant_id()) :: {:ok, tenant()} | :error
Link to this function

fetch_tenant!(tenant_module, tenant_id)

@spec fetch_tenant!(tenant_module(), tenant_id()) :: tenant()
Link to this function

install(tenant_module, tenant_id, arg)

@spec install(tenant_module(), tenant_id(), {tenant_config(), tenant_capabilities()}) ::
  :ok | :async | {:error, :arleady_exists | term()}
Link to this function

uninstall(tenant_module, tenant_id)

@spec uninstall(tenant_module(), tenant_id()) ::
  :ok | :async | {:error, :tenant_not_found | term()}
Link to this function

update(tenant_module, tenant_id, arg)

@spec update(tenant_module(), tenant_id(), {tenant_config(), tenant_capabilities()}) ::
  :ok | :async | {:error, :tenant_not_found | term()}
Link to this function

whereis(tenant_module, tenant_id)

@spec whereis(tenant_module(), tenant_id()) :: {:ok, pid()} | :error