Skip to content

Commit 2839a79

Browse files
codeonbc-devrevshashankcube
authored
Adding docs for event retries in snap-ins (#82)
* Init docs for snap-in configuration * init docs and fixes * rewrite * review comments * update configuration * Add code blocks to retry mechanism * Apply suggestions from code review Co-authored-by: Ben Colborn <[email protected]> * code review suggestions * Fix as per comments * add pages to sidebar nav * Review comments * Remove docs for retries for now as we finalize approach * remove snap-components link * Revert "Remove docs for retries for now as we finalize approach" This reverts commit 293238b. * fix path * Update fern/docs/pages/retry-mechanism.mdx Co-authored-by: Ben Colborn <[email protected]> * Update fern/docs/pages/retry-mechanism.mdx Co-authored-by: Ben Colborn <[email protected]> * Update fern/docs/pages/retry-mechanism.mdx Co-authored-by: Ben Colborn <[email protected]> --------- Co-authored-by: Ben Colborn <[email protected]> Co-authored-by: shashankcube <[email protected]>
1 parent 06eceba commit 2839a79

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

fern/docs/pages/retry-mechanism.mdx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Event reliability in DevRev snap-ins
2+
3+
The DevRev snap-ins platform offers event reliability features to ensure smooth and resilient event processing. This document provides an overview of these features and how developers can leverage them to build reliable snap-ins.
4+
5+
## Getting started
6+
7+
To start using the event reliability features in your Snap-ins, follow these steps:
8+
9+
1. Update your DevRev SDK to the latest version.
10+
2. Define retryable errors using the `FunctionExecutionError` interface in your Snap-in code.
11+
3. Configure the retry behavior in your snap-in manifest.
12+
4. Handle errors appropriately in your snap-in function.
13+
14+
## Retryable errors
15+
16+
Snap-ins can define retryable errors using the `FunctionExecutionError` interface provided by the DevRev SDK. This enables the platform to automatically retry events that encounter intermittent or transient errors, improving overall reliability.
17+
18+
## Retry configuration
19+
20+
Developers can configure the retry behavior of their snap-in functions using the snap-in manifest. The following options are available:
21+
22+
```yaml
23+
functions:
24+
- name: function_name
25+
config:
26+
runtime:
27+
max_retries: 5 # number of retries before failing the event
28+
min_interval: 120 # interval in seconds between each retry
29+
```
30+
31+
- `max_retries`: The maximum number of retries before marking the event as failed.
32+
- `min_interval`: The minimum interval in seconds between each retry attempt. This interval may be adjusted based on the timeout of the corresponding function.
33+
34+
## Error handling
35+
36+
The DevRev snap-in platform handles errors based on the ordering guarantees of the snap-in function.
37+
38+
For snap-in functions with relaxed ordering, non-retryable errors are marked as failed, and the errored event is propagated to the DevRev platform for tracking. Retryable errors are automatically retried based on the specified retry configuration. If the maximum number of retries is exhausted, the errored events are moved to a dead-letter queue (DLQ) for further handling.
39+
40+
## Error interface
41+
42+
The DevRev SDK defines the `FunctionExecutionError` type to represent errors returned from the snap-in's run function. Developers can use this type to provide additional error details and indicate whether an error is retryable.
43+
44+
```typescript
45+
class FunctionExecutionError extends Error {
46+
/**
47+
* Toggle to determine if the event should be retried or not. If not set or set to false,
48+
* the event is not retried.
49+
*/
50+
retry: boolean;
51+
52+
/**
53+
* Whether to retry the event payload with updated metadata
54+
* that platform provides. Useful when the event payload is
55+
* not in a state to be directly processed, and may need new
56+
* keyrings/service account tokens or new inputs.
57+
*/
58+
refresh?: boolean;
59+
60+
constructor(message: string, retry: boolean, refresh?: boolean) {
61+
super(message);
62+
this.retry = retry;
63+
this.refresh = refresh;
64+
}
65+
}
66+
```
67+
68+
## Example usage
69+
70+
Here's an example of how to use the `FunctionExecutionError` in your Snap-in code:
71+
72+
```typescript
73+
import { FunctionExecutionError } from '@devrev/typescript-sdk/dist/snap-ins/types';
74+
75+
export const run = async (events: any[]) => {
76+
/*
77+
Put your code here to handle the event.
78+
*/
79+
console.log('Events: ', JSON.stringify(events));
80+
81+
try {
82+
// Your event processing logic here
83+
// ...
84+
85+
// Retryable error
86+
console.log('Retrying....');
87+
const runtimeError = new FunctionExecutionError('Runtime Retryable Error', true, false);
88+
throw runtimeError;
89+
90+
// Non-retryable error
91+
// const runtimeError = new FunctionExecutionError("Runtime Non-Retryable Error", false, false);
92+
// throw runtimeError;
93+
94+
} catch (error) {
95+
if (error instanceof FunctionExecutionError) {
96+
throw error;
97+
} else {
98+
// Handle other types of errors
99+
// ...
100+
}
101+
}
102+
};
103+
104+
export default run;
105+
```
106+
107+
In this example, the Snap-in function's `run` method processes the events and can throw a `FunctionExecutionError` to indicate whether the error is retryable or not. The Snap-in platform handles the error based on the `retry` and `refresh` properties set in the error object.

fern/versions/public.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ navigation:
199199
path: ../docs/pages/best_practices.mdx
200200
- page: Locally testing snap-ins
201201
path: ../docs/pages/testing.mdx
202+
- page: Handling errors and retrying
203+
slug: handling-errors-and-retrying
204+
path: ../docs/pages/retry-mechanism.mdx
202205
- page: Debugging
203206
path: ../docs/pages/debugging.mdx
204207
- page: Quotas and limits

0 commit comments

Comments
 (0)