Skip to content

Commit 002a2c3

Browse files
altafDevRevAtul-Butolagithub-actions[bot]
authored
chore: add function synchronous execution doc (#285)
* chore: add function synchronous execution doc * Apply suggestions from code review Co-authored-by: Atul-Butola <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * rem: foobar * made suggested changes --------- Co-authored-by: Atul-Butola <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1e0dfa3 commit 002a2c3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

fern/docs/pages/references/functions.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,52 @@ functions:
2727
- `name`: It is the function name that should match the corresponding function name in the folder.
2828
- `description`: It describes the function.
2929

30+
### Synchronous execution with synchronization key
31+
32+
To ensure that function executions are processed in order, FIFO, for a given context such as a user or conversation, enable synchronization support in your function’s manifest and use a synchronization key, sync_id.
33+
34+
The platform uses the sync_id as the message group for FIFO processing. This ensures that all executions with the same sync_id are processed in order, preventing race conditions or duplicate conversations.
35+
Use cases for synchronous execution include:
36+
37+
- Ensuring order of message processing for chatbots or messaging integrations.
38+
- Preventing duplicate or out-of-order actions when multiple events are triggered.
39+
40+
To enable this:
41+
42+
1. Enable synchronization in manifest
43+
- In your function’s manifest, add the field:
44+
```yaml
45+
functions:
46+
- name: function_name
47+
description: Let me execute
48+
supports_synchronization: true
49+
```
50+
- This tells the platform to use a FIFO queue for this function.
51+
52+
1. Set the synchronization key
53+
- When triggering an automation, include the sync_id in your rego policy along with the `event_key`. For example:
54+
```rego rego
55+
package rego
56+
57+
output = {"event": event, "event_key": event_key, "sync_id": sync_id} {
58+
input.request.method == "POST"
59+
event := input.request.body
60+
event_key := "user-enter"
61+
sync_id := "1234567890"
62+
} else = {"response": response }{
63+
response := {
64+
"status_code": 400
65+
}
66+
}
67+
```
68+
69+
- The sync_id groups related executions for ordered processing.
70+
71+
3. Execution behavior
72+
- If `supports_synchronization` is true and a sync_id is provided, executions with the same sync_id are processed in order.
73+
- If no sync_id is provided, executions are grouped by a random string.
74+
- If `supports_synchronization` is false, the sync_id is ignored and executions are processed as usual.
75+
3076

3177
<Callout intent="note">
3278
Each function should be registered in `src/function-factory.ts` to be available for execution.

0 commit comments

Comments
 (0)