smart_city_data v2.1.5 SmartCity.Data View Source
Message struct shared amongst all SmartCity microservices.
const DataMessage = {
"dataset_id": "", // UUID
"payload": {},
"_metadata": { // cannot be used safely
"orgName": "", // ~r/^[a-zA-Z_]+$/
"dataName": "", // ~r/^[a-zA-Z_]+$/
"stream": true
},
"operational": {
"timing": [{
"startTime": "", // iso8601
"endTime": "", // iso8601
"app": "", // microservice generating timing data
"label": "" // label for this particular timing data
}]
}
}
Link to this section Summary
Functions
Adds a SmartCity.Data.Timing
to the list of timings in this SmartCity.Data
. The timing will be validated to ensure both start and end times have been set.
Encodes SmartCity.Data
into JSON. Typically used right before sending as a Kafka message.
Encodes SmartCity.Data
into JSON. Typically used right before sending as a Kafka message.
Get all timings on this Data
Returns a new SmartCity.Data
struct. SmartCity.Data.Timing
structs will be created along the way.
Creates a new SmartCity.Data
struct using new/1
and adds timing information to the message.
Transforms the SmartCity.Data
payload
field with the given unary function and replaces it in the message.
Link to this section Types
payload()
View Source
payload() :: String.t()
payload() :: String.t()
Link to this section Functions
add_timing(message, new_timing)
View Source
add_timing(SmartCity.Data.t(), SmartCity.Data.Timing.t()) :: SmartCity.Data.t()
add_timing(SmartCity.Data.t(), SmartCity.Data.Timing.t()) :: SmartCity.Data.t()
Adds a SmartCity.Data.Timing
to the list of timings in this SmartCity.Data
. The timing will be validated to ensure both start and end times have been set.
Returns a SmartCity.Data
struct with new_timing
prepended to existing timings list.
Parameters
- message: A
SmartCity.Data
- new_timing: A timing you want to add. Must have
start_time
andend_time
set
encode(message)
View Source
encode(SmartCity.Data.t()) ::
{:ok, String.t()} | {:error, Jason.EncodeError.t() | Exception.t()}
encode(SmartCity.Data.t()) :: {:ok, String.t()} | {:error, Jason.EncodeError.t() | Exception.t()}
Encodes SmartCity.Data
into JSON. Typically used right before sending as a Kafka message.
encode!(message)
View Source
encode!(SmartCity.Data.t()) :: String.t()
encode!(SmartCity.Data.t()) :: String.t()
Encodes SmartCity.Data
into JSON. Typically used right before sending as a Kafka message.
Raises an error if it fails to convert to a JSON string.
get_all_timings(data)
View Source
get_all_timings(SmartCity.Data.t()) :: [SmartCity.Data.Timing.t()]
get_all_timings(SmartCity.Data.t()) :: [SmartCity.Data.Timing.t()]
Get all timings on this Data
Returns a list of SmartCity.Data.Timing
structs or []
Parameters
- data_message: The message to extract timings from
new(msg)
View Source
new(map() | String.t()) :: {:ok, SmartCity.Data.t()}
new(map() | String.t()) :: {:ok, SmartCity.Data.t()}
Returns a new SmartCity.Data
struct. SmartCity.Data.Timing
structs will be created along the way.
Can be created from:
- map with string keys
- map with atom keys
- JSON
Examples
iex> SmartCity.Data.new(%{dataset_id: "a_guid", payload: "the_data", _metadata: %{org: "scos", name: "example"}, operational: %{timing: [%{app: "app name", label: "function name", start_time: "2019-05-06T19:51:41+00:00", end_time: "2019-05-06T19:51:51+00:00"}]}})
{:ok, %SmartCity.Data{
dataset_id: "a_guid",
payload: "the_data",
_metadata: %{org: "scos", name: "example"},
operational: %{
timing: [%SmartCity.Data.Timing{ app: "app name", end_time: "2019-05-06T19:51:51+00:00", label: "function name", start_time: "2019-05-06T19:51:41+00:00"}]
}
}}
timed_new(msg, app)
View Source
timed_new(map(), String.t()) :: SmartCity.Data.t()
timed_new(map(), String.t()) :: SmartCity.Data.t()
Creates a new SmartCity.Data
struct using new/1
and adds timing information to the message.
Returns a SmartCity.Data
struct with new_timing
prepended to existing timings list.
Parameters
- message: A
SmartCity.Data
- app: The application that is asking to create the new
SmartCity.Data
. Ex.reaper
orvoltron
timed_transform(msg, app, function)
View Source
timed_transform(
SmartCity.Data.t(),
String.t(),
(payload() -> {:ok, term()} | {:error, term()})
) :: SmartCity.Data.t()
timed_transform( SmartCity.Data.t(), String.t(), (payload() -> {:ok, term()} | {:error, term()}) ) :: SmartCity.Data.t()
Transforms the SmartCity.Data
payload
field with the given unary function and replaces it in the message.
Additionally, returns a SmartCity.Data
struct with new_timing
prepended to existing timings list.
Parameters
- message: A
SmartCity.Data
- app: The application that is asking to create the new
SmartCity.Data
. Ex.reaper
orvoltron
- function: an arity 1 (/1) function that will transform the payload in the provided message