|
| 1 | +import { Callout, Card, Cards, Steps, Tabs } from "nextra/components"; |
| 2 | +import UniversalTabs from "@/components/UniversalTabs"; |
| 3 | +import { GithubSnippet, getSnippets } from "@/components/code"; |
| 4 | + |
| 5 | +export const DurableGo = { |
| 6 | + path: "examples/v1/workflows/durable-event.go", |
| 7 | +}; |
| 8 | + |
| 9 | +export const DurableTs = { |
| 10 | + path: "src/v1/examples/durable-event/workflow.ts", |
| 11 | +}; |
| 12 | + |
| 13 | +export const DurablePy = { |
| 14 | + path: "examples/durable_event/worker.py", |
| 15 | +}; |
| 16 | + |
| 17 | +export const getStaticProps = ({}) => |
| 18 | + getSnippets([DurableGo, DurableTs, DurablePy]); |
| 19 | + |
| 20 | +## Durable Events |
| 21 | + |
| 22 | +Durable events are a feature of **durable tasks** which allow tasks to wait for an event to occur before continuing. This is useful in cases where a task needs to wait for a long time for an external action. Durable events are useful, because even if your task is interrupted and requeued while waiting for an event, the event will still be processed. When the task is resumed, it will read the event from the durable event log and continue processing. |
| 23 | + |
| 24 | +## Declaring durable events |
| 25 | + |
| 26 | +Durable events are declared using the context method `WaitFor` (or utility method `WaitForEvent`) on the `DurableContext` object. |
| 27 | + |
| 28 | +<UniversalTabs items={["Python", "Typescript", "Go"]}> |
| 29 | + <Tabs.Tab title="Python"> |
| 30 | + |
| 31 | +<GithubSnippet src={DurablePy} target="Durable Event" /> |
| 32 | + |
| 33 | +</Tabs.Tab> |
| 34 | +<Tabs.Tab title="Typescript"> |
| 35 | + |
| 36 | +<GithubSnippet src={DurableTs} target="Durable Event" /> |
| 37 | + |
| 38 | +</Tabs.Tab> |
| 39 | +<Tabs.Tab title="Go"> |
| 40 | + |
| 41 | +<GithubSnippet src={DurableGo} target="Durable Event" /> |
| 42 | + |
| 43 | +</Tabs.Tab> |
| 44 | +</UniversalTabs> |
| 45 | + |
| 46 | +## Durable event filters |
| 47 | + |
| 48 | +Durable events can be filtered using [CEL](https://github.com/google/cel-spec) expressions. For example, to only receive `user:update` events for a specific user, you can use the following filter: |
| 49 | + |
| 50 | +<UniversalTabs items={["Python", "Typescript", "Go"]}> |
| 51 | + <Tabs.Tab title="Python"> |
| 52 | + |
| 53 | +<GithubSnippet src={DurablePy} target="Durable Event With Filter" /> |
| 54 | + |
| 55 | +</Tabs.Tab> |
| 56 | +<Tabs.Tab title="Typescript"> |
| 57 | + |
| 58 | +<GithubSnippet src={DurableTs} target="Durable Event With Filter" /> |
| 59 | + |
| 60 | +</Tabs.Tab> |
| 61 | +<Tabs.Tab title="Go"> |
| 62 | + |
| 63 | +<GithubSnippet src={DurableGo} target="Durable Event With Filter" /> |
| 64 | + |
| 65 | +</Tabs.Tab> |
| 66 | +</UniversalTabs> |
0 commit comments