commit | 49008c9b2c581ebf725b3aa0cb922a022d09d627 | [log] [tgz] |
---|---|---|
author | Mitch Fierro <sendtofierro@gmail.com> | Thu Feb 16 16:45:03 2017 -0800 |
committer | Mitch Fierro <sendtofierro@gmail.com> | Tue Feb 21 13:36:06 2017 -0800 |
tree | 7458beb4afa681d95818cfd6fd946fad56383c3b | |
parent | 745527bea92522b5abeafba4fda2ea5cff063933 [diff] |
Adds tests to ensure sync does not panic when various endpoints are unreachable
This core plugin for apid connects to the Apigee Change Agent and publishes the data changes events onto the apid Event service. It also coordinates DB initialization for plugins on startup.
name | description |
---|---|
apigeesync_poll_interval | int. seconds. default: 5 |
apigeesync_proxy_server_base | string. url. required. |
apigeesync_consumer_key | string. required. |
apigeesync_consumer_secret | string. required. |
This plugin also populates a configuration item for dependant plugins that may need it:
name | description |
---|---|
apigeesync_apid_instance_id | string |
Example plugin code:
var ( log apid.LogService // set in initPlugin data apid.DataService unsafeDB apid.DB dbMux sync.RWMutex ) func init() { apid.RegisterPlugin(initPlugin) } func initPlugin(services apid.Services) error { log = services.Log().ForModule("examplePlugin") log.Debug("start init") data = services.Data() return nil } // always use getDB() to safely access current DB func getDB() apid.DB { dbMux.RLock() db := unsafeDB dbMux.RUnlock() return db } func setDB(db apid.DB) { dbMux.Lock() if unsafeDB == nil { // init API on DB initialization (optional) go initAPI() } unsafeDB = db dbMux.Unlock() } func processSnapshot(snapshot *common.Snapshot) { log.Debugf("Snapshot received. Switching to DB version: %s", snapshot.SnapshotInfo) db, err := data.DBVersion(snapshot.SnapshotInfo) if err != nil { log.Panicf("Unable to access database: %v", err) } // init DB as needed (note: DB may exist, use 'CREATE TABLE IF NOT EXISTS' if not explicitly checking) initDB(db) for _, table := range snapshot.Tables { // populate tables from snapshot... } // switch to new database setDB(db) log.Debug("Snapshot processed") }