Beetle.check_rate
You're seeing just the function
check_rate
, go back to Beetle module for more information.
Specs
check_rate(id :: String.t(), scale_ms :: integer(), limit :: integer()) :: {:allow, count :: integer()} | {:deny, limit :: integer()} | {:error, reason :: any()}
Check if the action you wish to perform is within the bounds of the rate-limit.
Args:
id
: String name of the bucket. Usually the bucket name is comprised of some fixed prefix, with some dynamic string appended, such as an IP address or user id.scale_ms
: Integer indicating size of bucket in millisecondslimit
: Integer maximum count of actions within the bucket
Returns either {:allow, count}
, {:deny, limit}
or {:error, reason}
Example:
user_id = 42076
case check_rate("file_upload:#{user_id}", 60_000, 5) do
{:allow, _count} ->
# do the file upload
{:deny, _limit} ->
# render an error page or something
end
Specs
check_rate( backend :: atom(), id :: String.t(), scale_ms :: integer(), limit :: integer() ) :: {:allow, count :: integer()} | {:deny, limit :: integer()} | {:error, reason :: any()}
Same as check_rate/3, but allows specifying a backend