commit | 6849c7a3c7b80d1f493008388901000c94ef9d0b | [log] [tgz] |
---|---|---|
author | Sundar Ramamoorthy <sramamoorthy73@users.noreply.github.com> | Tue Apr 11 19:59:12 2017 -0700 |
committer | Scott Ganyo <scott@ganyo.com> | Tue Apr 11 19:59:12 2017 -0700 |
tree | 8958b3ce92a790775706629977232b359a603521 | |
parent | f0b9f21f2f86359ff77cf458c656b46bcd5b7ff1 [diff] |
Have a single client connection and reuse (#43) * Reuse a single client connection. * Add more connections for the tests. * Default is to cache conns. * Declare the client at the package level. It is thread safe anyway. * remove nil assignment of re-direct. * Set the re-direct as part of init. * Remove pointess calling of http.client via a function.
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. |
apigeesync_instance_name | string. optional. Display Name for UI |
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") }