View Source SmartCity.Data.Timing (smart_city v6.0.0)
Timing struct for adding timing metrics to SmartCity.Data
messages
Link to this section Summary
Functions
Gets the current time. This function should always be used for generating times to be used in timings to ensure consistency across all services.
Wraps the results of a function call with measured timing information
Creates a new SmartCity.Data.Timing
from opts.
Creates a new SmartCity.Data.Timing
struct, passing in all fields.
Validate that all required keys are present and valid (not nil).
Validate that all required keys are present and valid (not nil).
Link to this section Types
@type t() :: %SmartCity.Data.Timing{ app: String.t(), end_time: DateTime.t(), label: String.t(), start_time: DateTime.t() }
Link to this section Functions
@spec current_time() :: String.t()
Gets the current time. This function should always be used for generating times to be used in timings to ensure consistency across all services.
Returns current UTC Time in ISO8601 format
@spec measure(String.t(), String.t(), (() -> {:ok, term()} | {:error, term()})) :: {:ok, term(), t()} | {:error, String.t()}
Wraps the results of a function call with measured timing information
Returns {:ok, result
, timing
} on success, or {:error, reason
} on failure
@spec new( %{ :app => term(), :label => term(), optional(:start_time) => term(), optional(:end_time) => term() } | list() ) :: t()
Creates a new SmartCity.Data.Timing
from opts.
Returns a SmartCity.Data.Timing
struct or raises ArgumentError
parameters
Parameters
- opts: Keyword list or map containing struct attributes
Required keys: `app`, `label` See `Kernel.struct!/2`.
Creates a new SmartCity.Data.Timing
struct, passing in all fields.
Returns a SmartCity.Data.Timing
struct or raises ArgumentError
.
parameters
Parameters
- app: application for which timing metrics are being measured
- label: description of timing measurement
- start_time: time when measurement has begun
- end_time: time when measurement has finished
examples
Examples
iex> SmartCity.Data.Timing.new("foo", "bar", "not_validated", "not_validated")
%SmartCity.Data.Timing{
app: "foo",
label: "bar",
start_time: "not_validated",
end_time: "not_validated"
}
Validate that all required keys are present and valid (not nil).
Set by @validate_keys
module attribute.
Currently checks: app
, label
Returns {:ok, timing}
on success or {:error, reason}
on failure
parameters
Parameters
- timing: The
SmartCity.Data.Timing
struct to validate
Validate that all required keys are present and valid (not nil).
Returns timing
on success, or raises ArgumentError
on failure
See validate/1