Skip to content

Instantly share code, notes, and snippets.

@schmichael
Created November 22, 2025 00:39
Show Gist options
  • Select an option

  • Save schmichael/247a39bf36406c08c8a95fc8c85bd56a to your computer and use it in GitHub Desktop.

Select an option

Save schmichael/247a39bf36406c08c8a95fc8c85bd56a to your computer and use it in GitHub Desktop.
package main
import (
"context"
"log"
"github.com/hashicorp/nomad/api"
)
func main() {
config := api.DefaultConfig()
//config.Address = url
client, err := api.NewClient(config)
if err != nil {
return
}
defer client.Close()
topics := map[api.Topic][]string{
//api.TopicJob: {"*"},
api.TopicAllocation: {"*"},
}
ctx, _ := context.WithCancel(context.Background())
stream, err := client.EventStream().Stream(ctx, topics, 0, &api.QueryOptions{})
if err != nil {
log.Fatalf("error streaming: %v", err)
}
for {
select {
case events, ok := <-stream:
if !ok {
log.Fatalf("stream close")
}
if events.Err != nil {
log.Printf("error in stream: %v", events.Err)
}
log.Printf("event (%d) %v", len(events.Events), events.Events)
case <-ctx.Done():
log.Printf("Nomad Job stop")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment