|
@@ -2,7 +2,6 @@ package docker
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
-
|
|
|
|
"sync"
|
|
"sync"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
@@ -71,6 +70,7 @@ var (
|
|
timer *time.Timer
|
|
timer *time.Timer
|
|
interval = 30000 * time.Millisecond
|
|
interval = 30000 * time.Millisecond
|
|
mu sync.Mutex
|
|
mu sync.Mutex
|
|
|
|
+ cancelFunc context.CancelFunc
|
|
)
|
|
)
|
|
|
|
|
|
func DebouncedExportDocker() {
|
|
func DebouncedExportDocker() {
|
|
@@ -78,45 +78,60 @@ func DebouncedExportDocker() {
|
|
defer mu.Unlock()
|
|
defer mu.Unlock()
|
|
|
|
|
|
if timer != nil {
|
|
if timer != nil {
|
|
|
|
+ if cancelFunc != nil {
|
|
|
|
+ cancelFunc() // cancel the previous context
|
|
|
|
+ }
|
|
timer.Stop()
|
|
timer.Stop()
|
|
}
|
|
}
|
|
|
|
|
|
- timer = time.AfterFunc(interval, ExportDocker)
|
|
|
|
|
|
+ // Create a new context and cancelFunc
|
|
|
|
+ ctx, newCancelFunc := context.WithCancel(context.Background())
|
|
|
|
+ cancelFunc = newCancelFunc
|
|
|
|
+
|
|
|
|
+ timer = time.AfterFunc(interval, func() {
|
|
|
|
+ select {
|
|
|
|
+ case <-ctx.Done():
|
|
|
|
+ // if the context was canceled, don't execute ExportDocker
|
|
|
|
+ return
|
|
|
|
+ default:
|
|
|
|
+ ExportDocker()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
func onDockerStarted(containerID string) {
|
|
func onDockerStarted(containerID string) {
|
|
utils.Debug("onDockerStarted: " + containerID)
|
|
utils.Debug("onDockerStarted: " + containerID)
|
|
BootstrapContainerFromTags(containerID)
|
|
BootstrapContainerFromTags(containerID)
|
|
- DebouncedExportDocker()
|
|
|
|
|
|
+ // DebouncedExportDocker()
|
|
}
|
|
}
|
|
|
|
|
|
func onDockerDestroyed(containerID string) {
|
|
func onDockerDestroyed(containerID string) {
|
|
utils.Debug("onDockerDestroyed: " + containerID)
|
|
utils.Debug("onDockerDestroyed: " + containerID)
|
|
- DebouncedExportDocker()
|
|
|
|
|
|
+ // DebouncedExportDocker()
|
|
}
|
|
}
|
|
|
|
|
|
func onNetworkDisconnect(networkID string) {
|
|
func onNetworkDisconnect(networkID string) {
|
|
utils.Debug("onNetworkDisconnect: " + networkID)
|
|
utils.Debug("onNetworkDisconnect: " + networkID)
|
|
DebouncedNetworkCleanUp(networkID)
|
|
DebouncedNetworkCleanUp(networkID)
|
|
- DebouncedExportDocker()
|
|
|
|
|
|
+ // DebouncedExportDocker()
|
|
}
|
|
}
|
|
|
|
|
|
func onDockerCreated(containerID string) {
|
|
func onDockerCreated(containerID string) {
|
|
utils.Debug("onDockerCreated: " + containerID)
|
|
utils.Debug("onDockerCreated: " + containerID)
|
|
- DebouncedExportDocker()
|
|
|
|
|
|
+ // DebouncedExportDocker()
|
|
}
|
|
}
|
|
|
|
|
|
func onNetworkDestroy(networkID string) {
|
|
func onNetworkDestroy(networkID string) {
|
|
utils.Debug("onNetworkDestroy: " + networkID)
|
|
utils.Debug("onNetworkDestroy: " + networkID)
|
|
- DebouncedExportDocker()
|
|
|
|
|
|
+ // DebouncedExportDocker()
|
|
}
|
|
}
|
|
|
|
|
|
func onNetworkCreate(networkID string) {
|
|
func onNetworkCreate(networkID string) {
|
|
utils.Debug("onNetworkCreate: " + networkID)
|
|
utils.Debug("onNetworkCreate: " + networkID)
|
|
- DebouncedExportDocker()
|
|
|
|
|
|
+ // DebouncedExportDocker()
|
|
}
|
|
}
|
|
|
|
|
|
func onNetworkConnect(networkID string) {
|
|
func onNetworkConnect(networkID string) {
|
|
utils.Debug("onNetworkConnect: " + networkID)
|
|
utils.Debug("onNetworkConnect: " + networkID)
|
|
- DebouncedExportDocker()
|
|
|
|
|
|
+ // DebouncedExportDocker()
|
|
}
|
|
}
|