Shared state Task
Shared state Task allows for easy sharing of data between Process executions in a single Process or between all Processes in an Agent Group with a shared database.
Different commands for the shape are:
AddOrUpdate - If the Key exists the existing value will be updated, otherwise the Key/value pair will be added to the store
GetOrAdd - If the Key exists the Value will be retrieved, otherwise the Key/value pair given in the parameters will be added to the store.
TryAdd - If the Key does not exist the Key/value pair will be added to the store.
TryGetValue - If the Key exists the Value will be retrieved.
TryRemove - If the Key exists the Key/value pair will be removed from the store.
TryUpdate - If the Key exists the Value will be updated
GetTTL - Get the time to live for a Key.
UpdateTTL - Update the time to live for a Key.
Parameters
Key - All of the commands have a 'Key' parameter. The Key parameter is an expression and is used for deciding which value to fetch or where to update/add a value.
Value - Add and Update commands have a parameter called 'Value'. This is the value that is either added or updated for the KJey, this value needs to be JSON serializable.
Time to live - (TTL) parameter can be configured to decide how long a Key should be kept in store before purging the Key/value pair. Add and Update commands will refresh this TTL. GetOrAdd command will not refresh the TTL if the Key already exists in the store. The maximum TTL is 30 days and the minimum is 1 minute.
Throw an exception on failure - if the shared state command fails for some reason, for example TryAdd is used but the Key already exists and this parameter is set the Shared state Task will fail in an exception that needs to be handled on the Process side, otherwise the Process execution will end. If this is not set and the command fails the Shared state result will contain the information that the command failed.
Available for all Processes in an Agent Group - If this parameter is set the Key/value pair will be accessible for all Processes inside that Agent Group. If the parameter is not set only the single Process has access to this Key/value pair.
If a Key is added with this parameter set you will not be able to retrieve the Key/value pair with a Shared state command that does not have the parameter set.
Result of Shared state Task
The Shared state Element's result is an object with the following properties:
Success - boolean (true/false) indicates whether the command was successful or not.
Value - If the command returns a Value it will be of type dynamic.
Message - Textual information about the command execution to help with development and debugging.
The result properties can be directly accessed in the Processed with, for example, references #result.Value or #result.Success
Usage of Shared state Task
Now in the Process the expression #result.Value.Amount would have the value of 108.
Note: The Agents in the Agent Group must have a shared database configured for the Agents to share the cached values.
The next article is Introduction to Triggers in Frends
โ