You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// store additional retrieved data in state for use later in job
77
78
fn(state=> {
@@ -89,10 +90,10 @@ fn(state => {
89
90
90
91
// cleanup state at the end before finishing job
91
92
fn(state=> {
92
-
state.data=null
93
-
state.users=null
94
-
state.posts=null
95
-
93
+
state.data=null;
94
+
state.users=null;
95
+
state.posts=null;
96
+
96
97
return state;
97
98
});
98
99
```
@@ -148,20 +149,31 @@ The input state looks like this:
148
149
149
150
### Cron triggered runs
150
151
151
-
When a run is triggered by a cron job, its input state will be the output of the **first step** from the previous run. This allows each subsequent run to know about previous runs. In other words, you can pass information from one run to another even if they happen days apart.
152
+
When a run is triggered by a cron job, its input state will be the final state
153
+
of the previous run. This allows each subsequent run to know about previous
154
+
runs. In other words, you can pass information from one run to another even if
155
+
they happen days apart.
152
156
153
-
**Example scenario**: You have a **daily sync at 9 AM** with a workflow that has 3 steps: (1) fetch patient records, (2) transform data, (3) send to database. On Monday, the **first step** processes records up to ID 1000 and outputs `{ lastProcessedId: 1000 }`. Even though steps 2 and 3 modify the state further, only the **first step's output** gets saved for the next cron run. On Tuesday at 9 AM, the cron job starts again with `{ lastProcessedId: 1000 }` from Monday's first step, so it knows to fetch records starting from ID 1001.
157
+
**Example scenario**: You have a **daily sync at 9 AM** with a workflow that has
158
+
3 steps: (1) fetch patient records, (2) transform data, (3) send to database. On
159
+
Monday, the workflow processes records up to ID 1000 and outputs
160
+
`{ lastProcessedId: 1000 }` as its final state. On Tuesday at 9 AM, the cron job
161
+
starts again with `{ lastProcessedId: 1000 }` as its input, so it knows to fetch
162
+
and process records starting from ID 1001.
154
163
155
-
The first time the workflow runs, the initial state will simply be an empty JavaScript object: `{}`
164
+
The first time the workflow runs, the initial state will simply be an empty
165
+
JavaScript object: `{}`
156
166
157
167
#### Overriding cron input
158
168
159
169
You can always manually run a cron-triggered workflow with:
170
+
160
171
-**Empty input**: `{}` - starts fresh without previous state.
161
172
-**Custom input**: Your own data to test specific scenarios.
162
173
-**Default input**: Uses the same input as the scheduled runs.
163
174
164
-
If the manual run succeeds, the next scheduled cron run will start with whatever output state your manual run produced.
175
+
If the manual run succeeds, the next scheduled cron run will start with whatever
0 commit comments