Packages

RIG, the Reactive Interaction Gateway, provides an easy (and scaleable) way to push messages from backend services to connected frontends (and vice versa).

Current section

Files

Jump to
rig lib rig rate_limit common.ex
Raw

lib/rig/rate_limit/common.ex

defmodule Rig.RateLimit.Common do
@moduledoc false
require Logger
alias Rig.RateLimit
def now_unix do
{megasecs, secs, microsecs} = :os.timestamp()
megasecs * 1_000_000 + secs + microsecs / 1_000_000
end
def ensure_table(table_name) do
heir_pid = Process.whereis(RateLimit.TableOwner)
:ets.new table_name, [:set, :public, :named_table, {:heir, heir_pid, :noargs}]
Logger.debug "Created ETS table #{inspect table_name}"
table_name
rescue
_ in ArgumentError ->
# This usually just means that the table already exists
table_name
end
end