retort v2.7.0 Retort.Resources.Timeout View Source
Timeouts for a module that use Retort.Resources can be configured for all Retort.Client.Generic calls.
Module Timeout
The default timeout is 5_000 milliseconds as is the default throughout OTP. A default timeout for all actions in
your module can be set.
Either as a config
config :retort, MyRPC.Authors
timeout: 10_000 # milliseconds
or at runtime in the Application environment
Retort.Resources.Timeout.put(MyRPC.Authors, 10_000)
Call Timeout
If only some of your Retort.Client.Generic calls are timing out (such as :index), you can set the timeout for just
that call.
Either as a config
config :retort, MyRPC.Authors,
timeout: [
index: 10_000 # milliseconds
]
or at runtime
Retort.Resources.Timeout.put(MyRPC.Authors, :index, 10_000)
The Calcinator.Resources callbacks implemented by use Retort.Resources call the following Retort.Client.Generic
calls.
NOTE: Calcinator.update/2 calls Calcinator.Resources.get/2 to get the pre-existing data to generate the changeset
for Calcinator.Resources.update/2, so either of those may timeout, so you may need to increase the :show timeout
if the Calcinator.Resources.get/2 part of the Calcinator.update/2 is what is timing out and not the update itself.
Link to this section Summary
Types
The name of a Retort.Client.Generic function call that can take a timeout
Functions
Default timeout (5 seconds / 5,000 milliseconds) for Retort.Client.Generic calls by use Retort.Resources modules
Deletes timeout configuration for module. The default/0 timeout will be used for all Retort.Client.Generic
calls
Deletes timeout configuration for function_name calls to Retort.Client.Generic made by module. The
default/0 timeout will be used instead
The configured timeout(s) for the module that called use Retort.Resources
The configured timeout for Retort.Client.Generic calls of function_name by module that called
use Retort.Resources
Like get/2, but ensures the timeout is not nil
Sets the timeout for all Retort.Client.Generic calls made by module that called use Retort.Resources
Sets the timeout for Retort.Client.Generic calls of function_name by module that called
use Retort.Resources
Sets the timeout for Retort.Client.Generic calls of function_name by module that called
use Retort.Resources during the duration of this function call. timeout is restored to its original value after
this function call returns
Link to this section Types
function_name() :: :create | :destroy | :index | :show | :update
The name of a Retort.Client.Generic function call that can take a timeout.
Link to this section Functions
Default timeout (5 seconds / 5,000 milliseconds) for Retort.Client.Generic calls by use Retort.Resources modules.
Deletes timeout configuration for module. The default/0 timeout will be used for all Retort.Client.Generic
calls.
delete(module(), function_name()) :: :ok
Deletes timeout configuration for function_name calls to Retort.Client.Generic made by module. The
default/0 timeout will be used instead.
If there is no timeout for the module, then delete still succeeds
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.get(module)
nil
iex> Retort.Resources.Timeout.delete(module, :index)
:ok
If there is no timeout for the function_name, then delete still succeeds
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.get(module, :index)
nil
iex> Retort.Resources.Timeout.delete(module, :index)
:ok
If there was previously a module-wide timeout, it is converted to per function name timeouts with no entry for
function_name. All other function names have the original module-wide timeout.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.delete(module, :update)
iex> Retort.Resources.Timeout.get(module)
[create: 10_000, destroy: 10_000, index: 10_000, show: 10_000]
If there was previously only a function name timeout for function_name then the entire timeout configuration is
removed for module
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :index, 15_000)
iex> Retort.Resources.Timeout.get(module)
[index: 15_000]
iex> Retort.Resources.Timeout.delete(module, :index)
iex> Retort.Resources.Timeout.get(module)
nil
If there was previously function name timeouts for other function names besides function_name then those valeus will
remain
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :destroy, 7_500)
iex> Retort.Resources.Timeout.put(module, :index, 15_000)
iex> Retort.Resources.Timeout.get(module)
[index: 15_000, destroy: 7_500]
iex> Retort.Resources.Timeout.delete(module, :destroy)
iex> Retort.Resources.Timeout.get(module)
[index: 15_000]
The configured timeout(s) for the module that called use Retort.Resources.
When there is no timeout configuration, nil will be returned
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.delete(module)
iex> Retort.Resources.Timeout.get(module)
nil
When there is module-wide timeout, that timeout will be returned
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.get(module)
10_000
When there are function_name-specific timeouts, the list of those timeouts will be returned
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :destroy, 10_000)
iex> Retort.Resources.Timeout.put(module, :index, 10_000)
iex> Retort.Resources.Timeout.get(module)
[index: 10_000, destroy: 10_000]
Returns
Keyword.t- MapsRetort.Client.Genericfunction name to its timeout. If a function name is not in theKeyword.t, then theRetort.Resources.Timeout.default/0should be used.timeout- The timeout for allRetort.Client.Genericcalls.nil- No timeouts are configured formodule. TheRetort.Resources.Timeout.default/0should be used.
get(module(), function_name()) :: timeout() | nil
The configured timeout for Retort.Client.Generic calls of function_name by module that called
use Retort.Resources.
When there is no timeout configuration for module, returns nil
iex> Retort.Resources.Timeout.get(Retort.TestAuthors, :index)
nil
When there is a module-wide timeout, but no function_name timeout, the module-wide timeout will be returned.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.get(module, :index)
10_000
When there are function name timeouts, but none for function_name, nil is returned.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :index, 10_000)
iex> Retort.Resources.Timeout.get(module, :show)
nil
If there is a function name timeout for function_name, it is returned.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :index, 10_000)
iex> Retort.Resources.Timeout.get(module, :index)
10_000
Returns
timeout- if timeout is configured forfunction_namenil- if timeout is not configured forfunction_nameormodule
get_or_default(module(), function_name()) :: timeout()
Like get/2, but ensures the timeout is not nil
If there is no timeout configuration for module, default/0 is returned.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.get(module)
nil
iex> Retort.Resources.Timeout.get_or_default(module, :index) == Retort.Resources.Timeout.default()
true
If there is a module-wide timeout, it is returned.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.get_or_default(module, :index)
10_000
If there are function name timeouts, but not for function_name, default/0 is returned.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :index, 10_000)
iex> Retort.Resources.Timeout.get_or_default(module, :show) == Retort.Resources.Timeout.default()
true
If there is a function name timeout for function_name, then it is returned.
iex> module = Retort.TestAuthors
iex> timeout = 10_000
iex> Retort.Resources.Timeout.put(module, :index, timeout)
iex> Retort.Resources.Timeout.get_or_default(module, :index) == timeout
true
Sets the timeout for all Retort.Client.Generic calls made by module that called use Retort.Resources
If no previous timeout was set for module, it will now have one
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.delete(module)
iex> Retort.Resources.Timeout.get(module)
nil
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.get(module)
10_000
If a previous, single timeout was set for module, it will be overridden
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, 7_500)
iex> Retort.Resources.Timeout.get(module)
7_500
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.get(module)
10_000
If a previous, per function_name timeout was set, then all those disappear and they will all share the module
timeout
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :index, 15_000)
iex> Retort.Resources.Timeout.put(module, :show, 7_500)
iex> Retort.Resources.Timeout.get(module)
[show: 7_500, index: 15_000]
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.get(module)
10_000
put(module(), function_name(), timeout()) :: :ok
Sets the timeout for Retort.Client.Generic calls of function_name by module that called
use Retort.Resources.
If there was previously no timeout configuration for module, then configuration for only function_name is added.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.get(module)
nil
iex> Retort.Resources.Timeout.put(module, :index, 10_000)
iex> Retort.Resources.Timeout.get(module)
[index: 10_000]
If there was previously a module-wide timeout, that timeout is applied to all other function names while the given
timeout is used for function_name.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, 10_000)
iex> Retort.Resources.Timeout.put(module, :index, 15_000)
iex> Retort.Resources.Timeout.get(module)
[create: 10_000, destroy: 10_000, index: 15_000, show: 10_000, update: 10_000]
If there was previously only a function name timeout for function_name, it is replaced.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :index, 10_000)
iex> Retort.Resources.Timeout.get(module)
[index: 10_000]
iex> Retort.Resources.Timeout.put(module, :index, 15_000)
iex> Retort.Resources.Timeout.get(module)
[index: 15_000]
If there was previous function name timeouts for other function names, a new entry for function_name is added with
timeout.
iex> module = Retort.TestAuthors
iex> Retort.Resources.Timeout.put(module, :index, 15_000)
iex> Retort.Resources.Timeout.get(module)
[index: 15_000]
iex> Retort.Resources.Timeout.put(module, :show, 10_000)
iex> Retort.Resources.Timeout.get(module)
[show: 10_000, index: 15_000]
put(module(), function_name(), timeout(), (() -> term())) :: term()
Sets the timeout for Retort.Client.Generic calls of function_name by module that called
use Retort.Resources during the duration of this function call. timeout is restored to its original value after
this function call returns.
The return value func is returned.
iex> Retort.Resources.Timeout.put Retort.TestAuthors, :index, 1, fn ->
...> {:error, :timeout}
...> end
{:error, :timeout}
Returns
term- Returns value returned from the passed function.