1- # State Management
1+ ## State Management
22
33flow provides several mechanisms for managing state across [ executable] ( executable.md ) runs. This guide explores how to use the data store
44and temporary directories to maintain state, as well as how to make execution decisions based on that state.
55
6- ## Data Store
6+ ### Data Store
77
88The data store is a key-value store that persists data across executions. It provides a simple way to share information
99between executables and maintain state between runs.
1010
11- ### Store Persistence Scope
11+ #### Store Persistence Scope
1212
1313Values in the data store have different persistence scopes depending on where they are set:
1414
1515- Values set outside an executable (using the CLI directly) persist across all executions until explicitly cleared
1616- Values set within an executable persist only across that executable's sub-executables (both serial and parallel)
1717- All values set within an executable are automatically cleared when the parent executable completes
1818
19- ### Managing Store Data
19+ #### Managing Store Data
2020
2121The data store can be managed at a global level in the CLI and within an executable's script. Here are the key operations:
2222
@@ -51,7 +51,7 @@ flow store clear
5151flow store clear --full
5252```
5353
54- ### Using the Store in Executables
54+ #### Using the Store in Executables
5555
5656Here's an example of how to use the data store within an executable:
5757
@@ -73,7 +73,7 @@ executables:
7373 echo "Last run: $(flow store get last-run)"
7474` ` `
7575
76- ### Store-Based Conditional Execution
76+ #### Store-Based Conditional Execution
7777
7878The data store's contents can be accessed in executable ` if` conditions using the `data` context variable. This allows for
7979dynamic execution paths based on stored values :
@@ -95,12 +95,12 @@ executables:
9595
9696See the [Conditional Execution](conditional.md) guide for more examples of using conditions in Flow.
9797
98- # # Temporary Directories
98+ # ## Temporary Directories
9999
100100Flow provides a special directory reference `f:tmp` that creates an isolated temporary directory for an executable. This
101101directory is automatically cleaned up when the executable completes.
102102
103- # ## Using Temporary Directories
103+ # ### Using Temporary Directories
104104
105105To use a temporary directory, set the `dir` field in your executable configuration :
106106
@@ -116,7 +116,7 @@ executables:
116116 make build
117117` ` `
118118
119- # ## Sharing Temporary Files
119+ # ### Sharing Temporary Files
120120
121121While temporary directories are isolated, you can share files between steps in a serial or parallel executable by using
122122the same temporary directory :
@@ -133,7 +133,7 @@ executables:
133133 - cmd: cat output.txt
134134` ` `
135135
136- # # Combining State Management Approaches
136+ # ## Combining State Management Approaches
137137
138138The data store and temporary directories can be used together for more complex state management :
139139
@@ -157,17 +157,3 @@ executables:
157157 - if: data["cleanup-enabled"] == "true"
158158 cmd: make clean
159159` ` `
160-
161- # ## Best Practices
162-
163- When managing state in Flow, consider the following :
164-
165- 1. Use the data store for :
166- - Sharing simple key-value data between executables
167- - Storing configuration that needs to persist between runs
168- - Managing feature flags and conditional execution
169-
170- 2. Use temporary directories for :
171- - Build and compilation workspaces
172- - Processing temporary files
173- - Isolating file operations between different executions
0 commit comments