Oi. Runtime. Session
(oi v0.7.0)
Copy Markdown
Session separates the whole application into several spaces where contains different steps, independent symbionts and storages.
Summary
Functions
Returns the per-session storage map if orchid_stratum is available.
Ensures a session is started and calls fun with session-scoped opts.
Functions
@spec instances(Oi.name()) :: Oi.Runtime.Registry.key()
@spec instances_tuple(Oi.name()) :: Oi.Runtime.Registry.via_tuple()
@spec stop(Oi.name()) :: :ok | {:error, :session_not_found}
Returns the per-session storage map if orchid_stratum is available.
The map can be merged into orchid_baggage:
%{meta_store: {EtsAdapter, ref}, blob_store: {EtsAdapter, ref}}Returns nil when orchid_stratum is not loaded or the session
was started without storage.
@spec tasks_tuple(Oi.name()) :: Oi.Runtime.Registry.via_tuple()
Ensures a session is started and calls fun with session-scoped opts.
fun receives a keyword list suitable for merging into Oi.run/2 or
Oi.execute/2:
:executor—Oi.Executor.TaskSup:executor_opts—[sup: Session.tasks_tuple(name)]:orchid_baggage—%{scope_id: name}:name— the session name
The session is not stopped when fun returns — sessions are
designed to be long-lived. Call stop/1 when done.
Example
Session.with_session("tenant-1", fn session ->
Oi.run(graph, Keyword.merge(session, data: %{greeter: %{name: "Alice"}}))
end)