Skip to main content
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);
from kernel import Kernel

kernel = Kernel()

response = kernel.invocations.follow(id="id")
print(response)
package main

import (
	"context"
	"fmt"

	"github.com/kernel/kernel-go-sdk"
)

func main() {
	ctx := context.Background()
	client := kernel.NewClient()

	stream := client.Invocations.FollowStreaming(ctx, "id", kernel.InvocationFollowParams{})
	defer stream.Close()

	for stream.Next() {
		event := stream.Current()
		if event.Event == "invocation_state" {
			fmt.Println(event.Invocation.Status)
		}
	}
	if err := stream.Err(); err != nil {
		panic(err)
	}
}

Example

Here’s an example showing how to handle streaming status updates:
Typescript/Javascript
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);
from kernel import Kernel

kernel = Kernel()

invocation = kernel.invocations.retrieve("rr33xuugxj9h0bkf1rdt2bet")
print(invocation.status)
package main

import (
	"context"
	"fmt"

	"github.com/kernel/kernel-go-sdk"
)

func main() {
	ctx := context.Background()
	client := kernel.NewClient()

	invocation, err := client.Invocations.Get(ctx, "rr33xuugxj9h0bkf1rdt2bet")
	if err != nil {
		panic(err)
	}
	fmt.Println(invocation.Status)
}