lib/dapr/client/state.rb in dapr-0.4.0 vs lib/dapr/client/state.rb in dapr-0.4.1
- old
+ new
@@ -12,10 +12,11 @@
include Client
include SemanticLogger::Loggable
attr_reader :store_name
+ Item = Struct.new(:data, :etag, :metadata)
Empty = Google::Protobuf::Empty
Runtime = Client::Runtime
GetBulkStateResponse = Runtime::GetBulkStateResponse
GetStateRequest = Runtime::GetBulkStateRequest
SaveStateRequest = Runtime::SaveStateRequest
@@ -51,14 +52,16 @@
#
# @return [Array<BulkStateItem>] Array of items returned by the state store
def get(keys, metadata: {})
logger.debug('Getting state', keys:, store_name:, metadata:)
response = singleton.get_bulk_state GetStateRequest.new(store_name:, keys:, metadata:)
- response.items
+ response.items.to_h { |i| [i.key, Item.new(data: i.data, etag: i.etag, metadata: i.metadata)] }
end
# @param states [Hash] states to set (key/values in the state store)
# @param metadata [Hash] metadata to include
+ #
+ # @return [Empty] The response from the Dapr State Management component (Empty means success)
def set(states, metadata: {})
states = states.map { |key, value| { key:, value:, metadata: } }
request = SaveStateRequest.new(store_name:, states:)
logger.debug('Setting state', states:, store_name:)
singleton.save_state request