Octoroom.Store behaviour (octoroom v0.1.0)

Copy Markdown View Source

Where Octoroom keeps what must outlive a room server or a node restart: room records and what workers save. A small key-value behaviour, so it can sit on ETS, Postgres or Redis.

Two tables:

  • :rooms: room id => %{run: run_id, assigns: map, updated_at: unix_ms}. Written when a room server starts and when its assigns change, deleted when the room stops because its last participant left. A record left behind means the room didn't stop cleanly, so the next room server with that id recovers it. Octoroom.Janitor deletes records whose room hasn't come back within a resume token's max age.
  • :workers: {room id, worker id} => whatever the worker last saved (the save: action of Octoroom.Worker), handed back as ctx.saved when it starts again. Deleted when the room stops the worker for good, when the room stops because its last participant left, when a fresh room with that id starts, and with the room's record by the janitor.

Workers' Cloudflare sessions need no records: each ends with its peer connection.

The store holds no participant state: participants come back through their resume tokens.

Configure with config :octoroom, store: {module, opts}. The default is {Octoroom.Store.ETS, []}.

Summary

Types

store()

@type store() :: {module(), keyword()}

table()

@type table() :: atom()

Callbacks

all(keyword, table)

@callback all(keyword(), table()) :: [{term(), term()}]

child_spec(keyword)

@callback child_spec(keyword()) :: Supervisor.child_spec() | nil

Child spec for the store's process, if it has one.

delete(keyword, table, key)

@callback delete(keyword(), table(), key :: term()) :: :ok

get(keyword, table, key)

@callback get(keyword(), table(), key :: term()) :: term() | nil

put(keyword, table, key, value)

@callback put(keyword(), table(), key :: term(), value :: term()) :: :ok

Functions

all(arg, table)

config()

@spec config() :: store()

The configured store.

delete(arg, table, key)

get(arg, table, key)

put(arg, table, key, value)