Skip to content

Commit 5f8072c

Browse files
authored
Chore/unify configurations (#319)
* refactor: update PluginManager to use configuration for various configurations - Replaced hardcoded values in PluginManager methods with values from the configuration. - Updated serverless plugin launch timeout and working paths to utilize the new configuration structure. - Enhanced local plugin runtime initialization to pull settings from the configuration, improving maintainability and flexibility. * refactor: clean up PluginManager by removing unused fields and updating platform check - Removed commented-out fields from PluginManager to enhance code clarity. - Updated platform check to utilize the configuration structure instead of a direct field reference, improving maintainability.
1 parent 412084b commit 5f8072c

5 files changed

Lines changed: 22 additions & 88 deletions

File tree

internal/core/plugin_manager/install_to_serverless.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (p *PluginManager) InstallToAWSFromPkg(
3535
}
3636

3737
// serverless.LaunchPlugin will check if the plugin has already been launched, if so, it returns directly
38-
response, err := serverless.LaunchPlugin(originalPackager, decoder, p.serverlessConnectorLaunchTimeout, false)
38+
response, err := serverless.LaunchPlugin(originalPackager, decoder, p.config.DifyPluginServerlessConnectorLaunchTimeout, false)
3939
if err != nil {
4040
return nil, err
4141
}
@@ -158,7 +158,7 @@ func (p *PluginManager) ReinstallToAWSFromPkg(
158158
response, err := serverless.LaunchPlugin(
159159
originalPackager,
160160
decoder,
161-
p.serverlessConnectorLaunchTimeout,
161+
p.config.DifyPluginServerlessConnectorLaunchTimeout,
162162
true, // ignoreIdempotent, true means always reinstall
163163
)
164164
if err != nil {

internal/core/plugin_manager/launcher.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (p *PluginManager) getLocalPluginRuntime(pluginUniqueIdentifier plugin_enti
4848

4949
identity := manifest.Identity()
5050
identity = strings.ReplaceAll(identity, ":", "-")
51-
pluginWorkingPath := path.Join(p.workingDirectory, fmt.Sprintf("%s@%s", identity, checksum))
51+
pluginWorkingPath := path.Join(p.config.PluginWorkingPath, fmt.Sprintf("%s@%s", identity, checksum))
5252
return &pluginRuntimeWithDecoder{
5353
runtime: plugin_entities.PluginRuntime{
5454
Config: manifest,
@@ -130,18 +130,18 @@ func (p *PluginManager) launchLocal(pluginUniqueIdentifier plugin_entities.Plugi
130130
}
131131

132132
localPluginRuntime := local_runtime.NewLocalPluginRuntime(local_runtime.LocalPluginRuntimeConfig{
133-
PythonInterpreterPath: p.pythonInterpreterPath,
134-
UvPath: p.uvPath,
135-
PythonEnvInitTimeout: p.pythonEnvInitTimeout,
136-
PythonCompileAllExtraArgs: p.pythonCompileAllExtraArgs,
137-
HttpProxy: p.HttpProxy,
138-
HttpsProxy: p.HttpsProxy,
139-
NoProxy: p.NoProxy,
140-
PipMirrorUrl: p.pipMirrorUrl,
141-
PipPreferBinary: p.pipPreferBinary,
142-
PipExtraArgs: p.pipExtraArgs,
143-
StdoutBufferSize: p.pluginStdioBufferSize,
144-
StdoutMaxBufferSize: p.pluginStdioMaxBufferSize,
133+
PythonInterpreterPath: p.config.PythonInterpreterPath,
134+
UvPath: p.config.UvPath,
135+
PythonEnvInitTimeout: p.config.PythonEnvInitTimeout,
136+
PythonCompileAllExtraArgs: p.config.PythonCompileAllExtraArgs,
137+
HttpProxy: p.config.HttpProxy,
138+
HttpsProxy: p.config.HttpsProxy,
139+
NoProxy: p.config.NoProxy,
140+
PipMirrorUrl: p.config.PipMirrorUrl,
141+
PipPreferBinary: *p.config.PipPreferBinary,
142+
PipExtraArgs: p.config.PipExtraArgs,
143+
StdoutBufferSize: p.config.PluginStdioBufferSize,
144+
StdoutMaxBufferSize: p.config.PluginStdioMaxBufferSize,
145145
})
146146
localPluginRuntime.PluginRuntime = plugin.runtime
147147
localPluginRuntime.BasicChecksum = basic_runtime.BasicChecksum{

internal/core/plugin_manager/manager.go

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ import (
2727
type PluginManager struct {
2828
m mapping.Map[string, plugin_entities.PluginLifetime]
2929

30-
// max size of a plugin package
31-
maxPluginPackageSize int64
32-
33-
// where the plugin finally running
34-
workingDirectory string
35-
36-
// where the plugin finally installed but not running
37-
pluginStoragePath string
38-
3930
// mediaBucket is used to manage media files like plugin icons, images, etc.
4031
mediaBucket *media_transport.MediaBucket
4132

@@ -54,52 +45,13 @@ type PluginManager struct {
5445
// backwardsInvocation is a handle to invoke dify
5546
backwardsInvocation dify_invocation.BackwardsInvocation
5647

57-
// python interpreter path
58-
pythonInterpreterPath string
59-
60-
// uv path
61-
uvPath string
62-
63-
// python env init timeout
64-
pythonEnvInitTimeout int
65-
66-
// proxy settings
67-
HttpProxy string
68-
HttpsProxy string
69-
NoProxy string
70-
71-
// pip mirror url
72-
pipMirrorUrl string
73-
74-
// pip prefer binary
75-
pipPreferBinary bool
76-
77-
// pip verbose
78-
pipVerbose bool
79-
80-
// pip extra args
81-
pipExtraArgs string
82-
83-
// python compileall extra args
84-
pythonCompileAllExtraArgs string
48+
config *app.Config
8549

8650
// remote plugin server
8751
remotePluginServer debugging_runtime.RemotePluginServerInterface
8852

8953
// max launching lock to prevent too many plugins launching at the same time
9054
maxLaunchingLock chan bool
91-
92-
// platform, local or serverless
93-
platform app.PlatformType
94-
95-
// serverless connector launch timeout
96-
serverlessConnectorLaunchTimeout int
97-
98-
pluginMaxExecutionTimeout int
99-
100-
// plugin stdio buffer size
101-
pluginStdioBufferSize int
102-
pluginStdioMaxBufferSize int
10355
}
10456

10557
var (
@@ -108,9 +60,6 @@ var (
10860

10961
func InitGlobalManager(oss oss.OSS, configuration *app.Config) *PluginManager {
11062
manager = &PluginManager{
111-
maxPluginPackageSize: configuration.MaxPluginPackageSize,
112-
pluginStoragePath: configuration.PluginInstalledPath,
113-
workingDirectory: configuration.PluginWorkingPath,
11463
mediaBucket: media_transport.NewAssetsBucket(
11564
oss,
11665
configuration.PluginMediaCachePath,
@@ -124,24 +73,9 @@ func InitGlobalManager(oss oss.OSS, configuration *app.Config) *PluginManager {
12473
oss,
12574
configuration.PluginInstalledPath,
12675
),
127-
localPluginLaunchingLock: lock.NewGranularityLock(),
128-
maxLaunchingLock: make(chan bool, 2), // by default, we allow 2 plugins launching at the same time
129-
pythonInterpreterPath: configuration.PythonInterpreterPath,
130-
uvPath: configuration.UvPath,
131-
pythonEnvInitTimeout: configuration.PythonEnvInitTimeout,
132-
pythonCompileAllExtraArgs: configuration.PythonCompileAllExtraArgs,
133-
platform: configuration.Platform,
134-
HttpProxy: configuration.HttpProxy,
135-
HttpsProxy: configuration.HttpsProxy,
136-
NoProxy: configuration.NoProxy,
137-
pipMirrorUrl: configuration.PipMirrorUrl,
138-
pipPreferBinary: *configuration.PipPreferBinary,
139-
pipVerbose: *configuration.PipVerbose,
140-
pipExtraArgs: configuration.PipExtraArgs,
141-
serverlessConnectorLaunchTimeout: configuration.DifyPluginServerlessConnectorLaunchTimeout,
142-
pluginStdioBufferSize: configuration.PluginStdioBufferSize,
143-
pluginStdioMaxBufferSize: configuration.PluginStdioMaxBufferSize,
144-
pluginMaxExecutionTimeout: configuration.PluginMaxExecutionTimeout,
76+
localPluginLaunchingLock: lock.NewGranularityLock(),
77+
maxLaunchingLock: make(chan bool, 2), // by default, we allow 2 plugins launching at the same time
78+
config: configuration,
14579
}
14680

14781
return manager
@@ -154,7 +88,7 @@ func Manager() *PluginManager {
15488
func (p *PluginManager) Get(
15589
identity plugin_entities.PluginUniqueIdentifier,
15690
) (plugin_entities.PluginLifetime, error) {
157-
if identity.RemoteLike() || p.platform == app.PLATFORM_LOCAL {
91+
if identity.RemoteLike() || p.config.Platform == app.PLATFORM_LOCAL {
15892
// check if it's a debugging plugin or a local plugin
15993
if v, ok := p.m.Load(identity.String()); ok {
16094
return v, nil

internal/core/plugin_manager/serverless.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (p *PluginManager) getServerlessPluginRuntime(
5252
PluginRuntime: runtimeEntity,
5353
LambdaURL: model.FunctionURL,
5454
LambdaName: model.FunctionName,
55-
PluginMaxExecutionTimeout: p.pluginMaxExecutionTimeout,
55+
PluginMaxExecutionTimeout: p.config.PluginMaxExecutionTimeout,
5656
}
5757

5858
if err := pluginRuntime.InitEnvironment(); err != nil {

internal/core/plugin_manager/watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func (p *PluginManager) startLocalWatcher() {
1515
go func() {
16-
log.Info("start to handle new plugins in path: %s", p.pluginStoragePath)
16+
log.Info("start to handle new plugins in path: %s", p.config.PluginInstalledPath)
1717
p.handleNewLocalPlugins()
1818
for range time.NewTicker(time.Second * 30).C {
1919
p.handleNewLocalPlugins()

0 commit comments

Comments
 (0)