Skip to main content

src/pharos@internal@spillover.erl

-module(pharos@internal@spillover).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/pharos/internal/spillover.gleam").
-export([from_table/1, table_name/1, table/1, start_link/2, child_spec/2, push/2, push_all/2, drain/1, size/1]).
-export_type([spillover/0]).

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

?MODULEDOC(false).

-opaque spillover() :: {spillover, gleam@erlang@atom:atom_()}.

-file("src/pharos/internal/spillover.gleam", 29).
?DOC(false).
-spec from_table(gleam@erlang@atom:atom_()) -> spillover().
from_table(Table) ->
    {spillover, Table}.

-file("src/pharos/internal/spillover.gleam", 37).
?DOC(false).
-spec table_name(gleam@erlang@process:name(any())) -> gleam@erlang@atom:atom_().
table_name(Name) ->
    pharos_ffi:name_to_atom(Name).

-file("src/pharos/internal/spillover.gleam", 40).
?DOC(false).
-spec table(spillover()) -> gleam@erlang@atom:atom_().
table(Spillover) ->
    erlang:element(2, Spillover).

-file("src/pharos/internal/spillover.gleam", 56).
?DOC(false).
-spec start_link(gleam@erlang@atom:atom_(), binary()) -> {ok,
        gleam@otp@actor:started(spillover())} |
    {error, gleam@otp@actor:start_error()}.
start_link(Table, Path) ->
    _pipe@2 = gleam@otp@actor:new_with_initialiser(
        1000,
        fun(_) ->
            pharos_ffi:spillover_open(Table, Path),
            _pipe = gleam@otp@actor:initialised({spillover, Table}),
            _pipe@1 = gleam@otp@actor:returning(_pipe, {spillover, Table}),
            {ok, _pipe@1}
        end
    ),
    gleam@otp@actor:start(_pipe@2).

-file("src/pharos/internal/spillover.gleam", 49).
?DOC(false).
-spec child_spec(gleam@erlang@atom:atom_(), binary()) -> gleam@otp@supervision:child_specification(spillover()).
child_spec(Table, Path) ->
    gleam@otp@supervision:worker(fun() -> start_link(Table, Path) end).

-file("src/pharos/internal/spillover.gleam", 70).
?DOC(false).
-spec push(spillover(), pharos@metric:metric()) -> nil.
push(Spillover, Metric) ->
    pharos_ffi:spillover_push(erlang:element(2, Spillover), Metric).

-file("src/pharos/internal/spillover.gleam", 76).
?DOC(false).
-spec push_all(spillover(), list(pharos@metric:metric())) -> nil.
push_all(Spillover, Metrics) ->
    pharos_ffi:spillover_push_all(erlang:element(2, Spillover), Metrics).

-file("src/pharos/internal/spillover.gleam", 82).
?DOC(false).
-spec drain(spillover()) -> list(pharos@metric:metric()).
drain(Spillover) ->
    pharos_ffi:spillover_drain(erlang:element(2, Spillover)).

-file("src/pharos/internal/spillover.gleam", 87).
?DOC(false).
-spec size(spillover()) -> integer().
size(Spillover) ->
    pharos_ffi:spillover_size(erlang:element(2, Spillover)).