pub struct WorkflowPersistence { /* private fields */ }Expand description
Workflow persistence manager
Handles saving and loading workflow contexts to/from disk. Files are stored in JSON format under:
~/.matrix/workflows/(user/global).matrix/workflows/(project-specific)
Implementations§
Source§impl WorkflowPersistence
impl WorkflowPersistence
Sourcepub fn new(project_dir: Option<&PathBuf>) -> Self
pub fn new(project_dir: Option<&PathBuf>) -> Self
Create a new persistence manager with project context
Searches both project and user directories when loading. Saves to project directory if available, else to user directory.
Sourcepub fn new_global() -> Self
pub fn new_global() -> Self
Create a persistence manager for user directory only (no project context)
Sourcepub fn with_base_path(base_path: PathBuf) -> Self
pub fn with_base_path(base_path: PathBuf) -> Self
Create a persistence manager with a custom base path
Useful for testing or custom configurations.
Sourcepub fn save(&self, context: &WorkflowContext) -> Result<()>
pub fn save(&self, context: &WorkflowContext) -> Result<()>
Save a workflow context to disk
The context is serialized to JSON and stored in the save directory (project directory if available, else user directory).
§Example
let persistence = WorkflowPersistence::new(Some(&project_path));
let ctx = WorkflowContext::new("my_workflow".to_string(), HashMap::new());
persistence.save(&ctx)?;Sourcepub fn load(&self, instance_id: &str) -> Result<Option<WorkflowContext>>
pub fn load(&self, instance_id: &str) -> Result<Option<WorkflowContext>>
Load a workflow context from disk
Searches both project and user directories.
Returns Ok(None) if the instance_id does not exist.
§Example
let persistence = WorkflowPersistence::new(Some(&project_path));
if let Some(ctx) = persistence.load("run-123")? {
println!("Loaded workflow: {}", ctx.workflow_id);
}Sourcepub fn list(&self) -> Result<Vec<WorkflowContext>>
pub fn list(&self) -> Result<Vec<WorkflowContext>>
List all saved workflow contexts from both directories
Returns a list of all persisted workflow contexts. Failed loads are logged and skipped.
§Example
let persistence = WorkflowPersistence::new(Some(&project_path));
let workflows = persistence.list()?;
for ctx in workflows {
println!("{}: {:?}", ctx.instance_id, ctx.status);
}Sourcepub fn list_by_status(
&self,
status: WorkflowStatus,
) -> Result<Vec<WorkflowContext>>
pub fn list_by_status( &self, status: WorkflowStatus, ) -> Result<Vec<WorkflowContext>>
Sourcepub fn project_path(&self) -> Option<&PathBuf>
pub fn project_path(&self) -> Option<&PathBuf>
Get the project path (if available)