Add Product Interfaces (#20403)
* app: improve plugin interfaces * add documentation * improve doc * add error id * add more info to readme
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7c1b8cd937
Коммит
39991d236b
@@ -50,6 +50,7 @@ type PrepackagedPlugin struct {
|
||||
// of active plugins.
|
||||
type Environment struct {
|
||||
registeredPlugins sync.Map
|
||||
registeredProducts sync.Map
|
||||
pluginHealthCheckJob *PluginHealthCheckJob
|
||||
logger *mlog.Logger
|
||||
metrics einterfaces.MetricsInterface
|
||||
@@ -300,6 +301,14 @@ func (env *Environment) Activate(id string) (manifest *model.Manifest, activated
|
||||
return pluginInfo.Manifest, true, nil
|
||||
}
|
||||
|
||||
func (env *Environment) AddProduct(productID string, hooks ProductHooks) {
|
||||
env.registeredProducts.Store(productID, newRegisteredProduct(productID, hooks))
|
||||
}
|
||||
|
||||
func (env *Environment) RemoveProduct(productID string) {
|
||||
env.registeredProducts.Delete(productID)
|
||||
}
|
||||
|
||||
func (env *Environment) RemovePlugin(id string) {
|
||||
if _, ok := env.registeredPlugins.Load(id); ok {
|
||||
env.registeredPlugins.Delete(id)
|
||||
@@ -481,6 +490,24 @@ func (env *Environment) RunMultiPluginHook(hookRunnerFunc func(hooks Hooks) bool
|
||||
return result
|
||||
})
|
||||
|
||||
env.registeredProducts.Range(func(key, value interface{}) bool {
|
||||
rp := value.(*registeredProduct)
|
||||
|
||||
if !rp.Implements(hookId) {
|
||||
return true
|
||||
}
|
||||
|
||||
hookStartTime := time.Now()
|
||||
result := hookRunnerFunc(rp.adapter)
|
||||
|
||||
if env.metrics != nil {
|
||||
elapsedTime := float64(time.Since(hookStartTime)) / float64(time.Second)
|
||||
env.metrics.ObservePluginMultiHookIterationDuration(rp.productID, elapsedTime)
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
if env.metrics != nil {
|
||||
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||
env.metrics.ObservePluginMultiHookDuration(elapsedTime)
|
||||
|
||||
Ссылка в новой задаче
Block a user