You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Libvirt service supports register event handler, so we can listen to events from libvirt directly in libvirt-provider and we don't need active pulling of information from libvirt.
I would suggest to subscribe to the `LifeCycleEvents` of the libvirt Domain and enqueue Machines if something changes in the domain.
Here is some sample code how this might look like:
// Subscribe to lifecycle events using the provided context
eventChan, err := l.LifecycleEvents(ctx)
if err != nil {
fmt.Println("Failed to subscribe to lifecycle events:", err)
return
}
fmt.Println("Subscribed to lifecycle events. Listening for events...")
// Listen for lifecycle events in a separate goroutine
go func() {
for event := range eventChan {
fmt.Printf("Received lifecycle event: %+v\n", event)
// enqueue Machines here and switch over the events
}
fmt.Println("Lifecycle event channel closed.")
}()
// Wait for context to be cancelled (e.g., by receiving a signal)
<-ctx.Done()
fmt.Println("Context cancelled. Shutting down...")
This can be also used to consolidate other go routines which we are starting during the initialization of the provider.
Summary
Libvirt service supports register event handler, so we can listen to events from libvirt directly in libvirt-provider and we don't need active pulling of information from libvirt.
Here is some sample code how this might look like:
This can be also used to consolidate other
go routines
which we are starting during the initialization of the provider.Originally posted by @afritzler in #144 (review)
The text was updated successfully, but these errors were encountered: