Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/invoke.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can invoke your app by making a `POST` request to Kernel's API or via the CL

### Asynchronous invocations

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.
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.

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

Expand Down
49 changes: 46 additions & 3 deletions apps/status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,54 @@ title: "Status"
---

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

Once you've [deployed](/apps/deploy) an app and invoked it, you can check its status.

<GetInvocationStatus />
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.

<Info>
An invocation ends once its code execution finishes.
</Info>

## Streaming Status Updates

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.

<GetInvocationEvents />

### Example

Here's an example showing how to handle streaming status updates:

```javascript
const result = await client.invocations.retrieve(invocation.id);

const follow = await client.invocations.follow(result.id);
for await (const evt of follow) {
if (evt.event === 'invocation_state') {
console.log(`Status: ${evt.invocation.status}`);

if (evt.invocation.status === 'succeeded') {
console.log('✅ Invocation completed successfully!');
if (evt.invocation.output) {
console.log('Result:', JSON.parse(evt.invocation.output));
}
} else if (evt.invocation.status === 'failed') {
console.log('❌ Invocation failed');
if (evt.invocation.status_reason) {
console.log('Error:', evt.invocation.status_reason);
}
}
} else if (evt.event === 'error') {
console.error('🚨 Error:', evt.error.message);
}
}

console.log('✅ Invocation successful!');
console.log('Invocation result:', JSON.stringify(result, null, 2));
```

## Polling Status Updates

Alternatively, you can poll the status endpoint using `retrieve` to check the invocation status periodically.

<GetInvocationStatus />
2 changes: 1 addition & 1 deletion snippets/openapi/get-invocations-id-events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ client = Kernel(
api_key="My API Key",
)
response = client.invocations.follow(
"id",
id="id",
)
print(response)
```
Expand Down