Bundle cleanup config, cleanup
diff --git a/apidGatewayDeploy_suite_test.go b/apidGatewayDeploy_suite_test.go index 803a8b3..dffb117 100644 --- a/apidGatewayDeploy_suite_test.go +++ b/apidGatewayDeploy_suite_test.go
@@ -40,11 +40,12 @@ Expect(err).NotTo(HaveOccurred()) SetDB(db) - debounceDuration = 1 * time.Millisecond + debounceDuration = time.Millisecond + bundleCleanupDelay = time.Millisecond router := apid.API().Router() // fake an unreliable bundle repo - backOffMultiplier = 10 * time.Millisecond + backOffMultiplier = time.Millisecond count := 1 router.HandleFunc("/bundles/{id}", func(w http.ResponseWriter, req *http.Request) { count++
diff --git a/cmd/apidGatewayDeploy/main.go b/cmd/apidGatewayDeploy/main.go index 546cc9d..46e75d4 100644 --- a/cmd/apidGatewayDeploy/main.go +++ b/cmd/apidGatewayDeploy/main.go
@@ -1,14 +1,14 @@ package main import ( + "encoding/json" "flag" "github.com/30x/apid" "github.com/30x/apid/factory" + "github.com/30x/apidGatewayDeploy" _ "github.com/30x/apidGatewayDeploy" "io/ioutil" - "github.com/30x/apidGatewayDeploy" "os" - "encoding/json" ) func main() { @@ -33,7 +33,6 @@ defer os.RemoveAll(tmpDir) configService.Set("data_path", tmpDir) - configService.Set("gatewaydeploy_bundle_dir", tmpDir) // todo: legacy? if deploymentsFile != "" { bytes, err := ioutil.ReadFile(deploymentsFile) @@ -114,7 +113,6 @@ LocalBundleURI: ad.URI, } - err = apiGatewayDeploy.InsertDeployment(tx, dep) if err != nil { log.Error("Unable to insert deployment") @@ -131,4 +129,4 @@ apiGatewayDeploy.InitAPI() return nil -} \ No newline at end of file +}
diff --git a/data.go b/data.go index 42f6efd..0f8c412 100644 --- a/data.go +++ b/data.go
@@ -65,7 +65,6 @@ PRIMARY KEY (id) ); `) - // todo: is ID enough? must it be scoped by cluster id? if err != nil { return err }
diff --git a/init.go b/init.go index 74a8548..70cdae2 100644 --- a/init.go +++ b/init.go
@@ -8,16 +8,18 @@ ) const ( - configBundleDirKey = "gatewaydeploy_bundle_dir" - configDebounceDuration = "gatewaydeploy_debounce_duration" + configBundleDirKey = "gatewaydeploy_bundle_dir" + configDebounceDuration = "gatewaydeploy_debounce_duration" + configBundleCleanupDelay = "gatewaydeploy_bundle_cleanup_delay" ) var ( - services apid.Services - log apid.LogService - data apid.DataService - bundlePath string - debounceDuration time.Duration + services apid.Services + log apid.LogService + data apid.DataService + bundlePath string + debounceDuration time.Duration + bundleCleanupDelay time.Duration ) func init() { @@ -31,13 +33,19 @@ config := services.Config() config.SetDefault(configBundleDirKey, "bundles") - config.SetDefault(configDebounceDuration, 1 * time.Second) + config.SetDefault(configDebounceDuration, time.Second) + config.SetDefault(configBundleCleanupDelay, time.Minute) debounceDuration = config.GetDuration(configDebounceDuration) - if debounceDuration < 1 * time.Millisecond { + if debounceDuration < time.Millisecond { log.Panicf("%s must be a positive duration", configDebounceDuration) } + bundleCleanupDelay = config.GetDuration(configBundleCleanupDelay) + if bundleCleanupDelay < time.Millisecond { + log.Panicf("%s must be a positive duration", configBundleCleanupDelay) + } + data = services.Data() relativeBundlePath := config.GetString(configBundleDirKey)
diff --git a/listener.go b/listener.go index 91f0fe4..889e74c 100644 --- a/listener.go +++ b/listener.go
@@ -6,6 +6,7 @@ "github.com/30x/apid" "github.com/apigee-labs/transicator/common" "os" + "time" ) const ( @@ -141,8 +142,7 @@ log.Debugf("will delete %d old bundles", len(bundlesToDelete)) go func() { // give clients a minute to avoid conflicts - // todo: configurable time - //time.Sleep(1 * time.Minute) + time.Sleep(bundleCleanupDelay) for _, b := range bundlesToDelete { log.Debugf("removing old bundle: %v", b) safeDelete(b)