Created
November 22, 2025 00:39
-
-
Save schmichael/247a39bf36406c08c8a95fc8c85bd56a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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