A new element in frends 5.4+

Shared state shapes 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 can be 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 key, 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. Maximum TTL is 30 days and minimum is 1 minute.

Throw an exception on failure - if the shared state command fails for some reason e.g. 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

The Shared state shapes 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 e.g #result.Value or #result.Success

Usage

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.

Did this answer your question?