JetPluginSDK.TenantMan behaviour (JetPluginSDK v0.1.5)
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()}
Link to this callback
handle_run({})
GenServer callbacks
@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
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