smart_city_data v3.0.2 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
Link to this section Functions
add_timing(message, new_timing)
View Sourceadd_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_timeandend_timeset
encode(message)
View Sourceencode(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.
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 Sourceget_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 Sourcenew(map() | String.t()) :: {:ok, SmartCity.Data.t()} | {:error, String.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 Sourcetimed_new(map(), String.t()) :: {:ok, SmartCity.Data.t()} | {:error, String.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.reaperorvoltron
timed_transform(msg, app, function)
View Sourcetimed_transform( SmartCity.Data.t(), String.t(), (payload() -> {:ok, term()} | {:error, term()}) ) :: {:ok, SmartCity.Data.t()} | {:error, String.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.reaperorvoltron - function: an arity 1 (/1) function that will transform the payload in the provided message