Use the callback functon to perform PostPluginit() once all plugins are initialized.
diff --git a/apigee_sync.go b/apigee_sync.go index 4aec8c2..bbdc8b3 100644 --- a/apigee_sync.go +++ b/apigee_sync.go
@@ -280,7 +280,7 @@ */ snapshotInfo = findSnapshotInfo(config.GetString(configScopeId)) if snapshotInfo == "" { - log.Fatalf("Snapshotserver comm error: [%s] ", err) + log.Fatalf("No local data, Snapshotserver comm error: [%s] ", err) } else { log.Error("Snapshot server down, Proceeding with local data") downloadSnapshot = true @@ -313,7 +313,7 @@ downloadSnapshot = true } } else { - log.Fatalf("Snapshot server Connect failed. Resp code %d", r.StatusCode) + log.Fatalf("Snapshot server conn failed. HTTP Resp code %d", r.StatusCode) } return err
diff --git a/init.go b/init.go index 844c98e..33e8297 100644 --- a/init.go +++ b/init.go
@@ -30,18 +30,20 @@ apid.RegisterPlugin(initPlugin) } -func postInitPlugins() { +func postInitPlugins(event apid.Event) { - log.Debug("start post plugin init") - /* call to Download Snapshot info */ - go DownloadSnapshot() + if event == apid.PluginsInitializedEvent { + log.Debug("start post plugin init") + /* call to Download Snapshot info */ + go DownloadSnapshot() - /* Begin Looking for changes periodically */ - log.Debug("starting update goroutine") - go updatePeriodicChanges() + /* Begin Looking for changes periodically */ + log.Debug("starting update goroutine") + go updatePeriodicChanges() - events.Listen(ApigeeSyncEventSelector, &handler{}) - log.Debug("Done post plugin init") + events.Listen(ApigeeSyncEventSelector, &handler{}) + log.Debug("Done post plugin init") + } } func initPlugin(services apid.Services) error { @@ -52,7 +54,12 @@ data = services.Data() events = services.Events() - events.Listen(apid.PluginsInitializedEvent, postInitPlugins) + /* This callback function will get called, once all the plugins are + * initialized (not just this plugin). This is needed because, + * DownloadSnapshots/Changes etc have to begin to be processed only + * after all the plugins are intialized + */ + events.ListenFunc(apid.SystemEventsSelector, postInitPlugins) config.SetDefault(configPollInterval, 120)