Skip to content

Commit

Permalink
duplex installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Sep 10, 2024
1 parent 8dd58b3 commit b23b52d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/core/plugin_manager/lifetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/langgenius/dify-plugin-daemon/internal/utils/log"
)

func (p *PluginManager) localLifetime(r plugin_entities.PluginFullDuplexLifetime) {
func (p *PluginManager) fullDuplexLifetime(r plugin_entities.PluginFullDuplexLifetime) {
configuration := r.Configuration()

log.Info("new plugin logged in: %s", configuration.Identity())
Expand Down
4 changes: 2 additions & 2 deletions internal/core/plugin_manager/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (p *PluginManager) startRemoteWatcher(config *app.Config) {
}()
go func() {
server.Wrap(func(rpr *remote_manager.RemotePluginRuntime) {
p.localLifetime(rpr)
p.fullDuplexLifetime(rpr)
})
}()
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func (p *PluginManager) handleNewLocalPlugins(config *app.Config) {
}()
// delete the plugin from the storage when the plugin is stopped
defer p.runningPluginInStorage.Delete(plugin.Runtime.State.AbsolutePath)
p.localLifetime(local_plugin_runtime)
p.fullDuplexLifetime(local_plugin_runtime)
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions internal/server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ func (app *App) redirectPluginInvokeByPluginIdentifier(
nodes, err := app.cluster.FetchPluginAvailableNodesById(plugin_unique_identifier.String())
if err != nil {
ctx.AbortWithStatusJSON(500, gin.H{"error": "Internal server error"})
log.Error("fetch plugin available nodes failed: %s", err.Error())
return
} else if len(nodes) == 0 {
ctx.AbortWithStatusJSON(404, gin.H{"error": "No available node"})
log.Error("no available node")
return
}

Expand Down
10 changes: 10 additions & 0 deletions internal/types/models/curd/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func CreatePlugin(
plugin_to_be_returns = &p
}

// remove exists installation
if err := db.DeleteByCondition(
models.PluginInstallation{
PluginID: plugin_to_be_returns.PluginID,
},
tx,
); err != nil {
return err
}

installation := &models.PluginInstallation{
PluginID: plugin_to_be_returns.PluginID,
PluginUniqueIdentifier: plugin_to_be_returns.PluginUniqueIdentifier,
Expand Down

0 comments on commit b23b52d

Please sign in to comment.