PipedreamHQ / PipedreamHQ/pipedream

Workflow state: how to throttle and drop events, or events tied to a specific group / key

Open
#1,969 1 comment 0 reactions 0 assignees View on GitHub
docs
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.