clara.rules.durability

Experimental namespace. This may change non-passively without warning.

Support for persisting Clara sessions to an external store. This will have two models: obtaining the full state of a session, and obtaining a “diff” of changes from a previous state.

See the session-state function to retrieve the full state of a session as a data structure that can be easily serialized via EDN or Fressian. Sessions can then be recovered with the restore-session-state function.

TODO: diff support is pending – functions for obtaining a diff of state from a previous point, allowing for a write-ahead log.

restore-session-state

(restore-session-state session {:keys [fact-counts], :as session-state})

Inputs: [session {:keys [fact-counts], :as session-state} :- session-state-schema]

Restore the given session to have the provided session state. The given session should be a newly-created session that was created with the same parameters as the session that was serialized. For instance, it should use the same rulesets, type function, and other settings.

This function returns a new session instance that reflects the given saved state. The returned session should be indistinguishable from the session that had its state saved.

session-state

(session-state session)

Inputs: [session] Returns: session-state-schema

Returns the state of a session as an EDN- or Fressian-serializable data structure. The returned structure contains only the minimal data necessary to reconstruct the session via the restore-session-state function below.

session-state-schema