PipedreamHQ / PipedreamHQ/pipedream
Workflow state: how to throttle and drop events, or events tied to a specific group / key
- Dominant language
- JavaScript
- Stars
- 11.7k
- Forks
- 5.8k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 102
Description
```javascript
const startTs = +new Date()
const lastExecutionTs = $checpoint
// If we receive a flood of events, only run the rest of our workflow on the first event and exit early for the rest
if (lastExecutionTs && (startTs - lastExecutionTs) < 5000) {
$end("Not running workflow. Too soon since last event")
}
// Save the current execution ts to $checkpoint
$checkpoint = startTs
```
```javascript
const key = steps.nodejs.$return_value
// Initialize checkpoint if $checkpoint is null
const checkpoint = $checkpoint ?? {}
const startTs = +new Date()
const lastExecutionTs = checkpoint[key]
// If we receive a flood of events, only run the rest of our workflow on the first event and exit early for the rest
if (lastExecutionTs && (startTs - lastExecutionTs) < 5000) {
$end("Not running workflow. Too soon since last event")
}
// Save the current execution ts to $checkpoint
checkpoint[key] = startTs
$checkpoint = checkpoint
```
Contributor guide
Assessment
This issue has not been assessed yet.