Status
Once you've deployed an app and invoked it, you can monitor its status using streaming for real-time updates or polling for periodic checks.
An invocation ends once its code execution finishes.
Streaming Status Updates
For real-time status monitoring, use follow to stream invocation events. This provides immediate updates as your invocation progresses and is more efficient than polling.
import Kernel from '@onkernel/sdk';
const kernel = new Kernel();
const response = await kernel.invocations.follow('id');
console.log(response);Example
Here's an example showing how to handle streaming status updates:
const result = await kernel.invocations.retrieve(invocation.id);
const follow = await kernel.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));
}
break;
} else if (evt.invocation.status === 'failed') {
console.log('Invocation failed');
if (evt.invocation.status_reason) {
console.log('Error:', evt.invocation.status_reason);
}
break;
}
} else if (evt.event === 'error') {
console.error('Error:', evt.error.message);
break;
}
}Polling Status Updates
Alternatively, you can poll the status endpoint using retrieve to check the invocation status periodically.
import Kernel from '@onkernel/sdk';
const kernel = new Kernel();
const invocation = await kernel.invocations.retrieve('rr33xuugxj9h0bkf1rdt2bet');
console.log(invocation.status);