Skip to content

Commit c67aa34

Browse files
Danny/kernel 364 documentation update async invocations section to use (#53)
* docs: update code samples from OpenAPI * Focus status page on streaming event status Focus the status page on streaming event status since that is our recommended solution. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3f6f90b commit c67aa34

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

apps/invoke.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can invoke your app by making a `POST` request to Kernel's API or via the CL
1515

1616
### Asynchronous invocations
1717

18-
For long running jobs, use asynchronous invocations to trigger Kernel actions without waiting for the result. You can then poll its [status](/apps/status) for the result.
18+
For long running jobs, use asynchronous invocations to trigger Kernel actions without waiting for the result. You can then stream real-time [status updates](/apps/status#streaming-status-updates) for the result.
1919

2020
<Info>Asynchronous invocations time out after 15 minutes.</Info>
2121

apps/status.mdx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,54 @@ title: "Status"
33
---
44

55
import GetInvocationStatus from '/snippets/openapi/get-invocations-id.mdx';
6+
import GetInvocationEvents from '/snippets/openapi/get-invocations-id-events.mdx';
67

7-
Once you've [deployed](/apps/deploy) an app and invoked it, you can check its status.
8-
9-
<GetInvocationStatus />
8+
Once you've [deployed](/apps/deploy) an app and invoked it, you can monitor its status using streaming for real-time updates or polling for periodic checks.
109

1110
<Info>
1211
An invocation ends once its code execution finishes.
1312
</Info>
13+
14+
## Streaming Status Updates
15+
16+
For real-time status monitoring, use `follow` to [stream invocation events](/api-reference/invocations/stream-invocation-events-via-sse). This provides immediate updates as your invocation progresses and is more efficient than polling.
17+
18+
<GetInvocationEvents />
19+
20+
### Example
21+
22+
Here's an example showing how to handle streaming status updates:
23+
24+
```javascript
25+
const result = await client.invocations.retrieve(invocation.id);
26+
27+
const follow = await client.invocations.follow(result.id);
28+
for await (const evt of follow) {
29+
if (evt.event === 'invocation_state') {
30+
console.log(`Status: ${evt.invocation.status}`);
31+
32+
if (evt.invocation.status === 'succeeded') {
33+
console.log('✅ Invocation completed successfully!');
34+
if (evt.invocation.output) {
35+
console.log('Result:', JSON.parse(evt.invocation.output));
36+
}
37+
} else if (evt.invocation.status === 'failed') {
38+
console.log('❌ Invocation failed');
39+
if (evt.invocation.status_reason) {
40+
console.log('Error:', evt.invocation.status_reason);
41+
}
42+
}
43+
} else if (evt.event === 'error') {
44+
console.error('🚨 Error:', evt.error.message);
45+
}
46+
}
47+
48+
console.log('✅ Invocation successful!');
49+
console.log('Invocation result:', JSON.stringify(result, null, 2));
50+
```
51+
52+
## Polling Status Updates
53+
54+
Alternatively, you can poll the status endpoint using `retrieve` to check the invocation status periodically.
55+
56+
<GetInvocationStatus />

snippets/openapi/get-invocations-id-events.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ client = Kernel(
1919
api_key="My API Key",
2020
)
2121
response = client.invocations.follow(
22-
"id",
22+
id="id",
2323
)
2424
print(response)
2525
```

0 commit comments

Comments
 (0)