Skip to content

Commit

Permalink
optimize: using identity to detect whether to use serverless or local…
Browse files Browse the repository at this point in the history
… plugin manager
  • Loading branch information
Yeuoly committed Dec 15, 2024
1 parent 53bd801 commit a401f99
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions internal/core/plugin_manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type PluginManager struct {

// max launching lock to prevent too many plugins launching at the same time
maxLaunchingLock chan bool

// platform, local or aws_lambda
platform app.PlatformType
}

var (
Expand Down Expand Up @@ -88,6 +91,7 @@ func InitGlobalManager(oss oss.OSS, configuration *app.Config) *PluginManager {
localPluginLaunchingLock: lock.NewGranularityLock(),
maxLaunchingLock: make(chan bool, 2), // by default, we allow 2 plugins launching at the same time
pythonInterpreterPath: configuration.PythonInterpreterPath,
platform: configuration.Platform,
}

return manager
Expand All @@ -100,17 +104,21 @@ func Manager() *PluginManager {
func (p *PluginManager) Get(
identity plugin_entities.PluginUniqueIdentifier,
) (plugin_entities.PluginLifetime, error) {
if v, ok := p.m.Load(identity.String()); ok {
return v, nil
}
if identity.RemoteLike() || p.platform == app.PLATFORM_LOCAL {
// check if it's a debugging plugin or a local plugin
if v, ok := p.m.Load(identity.String()); ok {
return v, nil
}
return nil, errors.New("plugin not found")
} else {
// otherwise, use serverless runtime instead
pluginSessionInterface, err := p.getServerlessPluginRuntime(identity)
if err != nil {
return nil, err
}

// check if plugin is a serverless runtime
pluginSessionInterface, err := p.getServerlessPluginRuntime(identity)
if err != nil {
return nil, err
return pluginSessionInterface, nil
}

return pluginSessionInterface, nil
}

func (p *PluginManager) GetAsset(id string) ([]byte, error) {
Expand Down

0 comments on commit a401f99

Please sign in to comment.