-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
132 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
package cluster | ||
|
||
import "github.com/langgenius/dify-plugin-daemon/internal/types/app" | ||
import ( | ||
"sync" | ||
|
||
"github.com/langgenius/dify-plugin-daemon/internal/types/app" | ||
) | ||
|
||
type Cluster struct { | ||
port uint16 | ||
} | ||
|
||
var ( | ||
cluster *Cluster | ||
) | ||
plugins map[string]*PluginLifeTime | ||
plugin_lock sync.Mutex | ||
} | ||
|
||
func Launch(config *app.Config) { | ||
cluster = &Cluster{ | ||
port: uint16(config.ServerPort), | ||
func NewCluster(config *app.Config) *Cluster { | ||
return &Cluster{ | ||
port: uint16(config.ServerPort), | ||
plugins: make(map[string]*PluginLifeTime), | ||
} | ||
|
||
go func() { | ||
cluster.clusterLifetime() | ||
}() | ||
} | ||
|
||
func GetCluster() *Cluster { | ||
return cluster | ||
func (c *Cluster) Launch(config *app.Config) { | ||
go c.clusterLifetime() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
package cluster | ||
|
||
import ( | ||
"github.com/langgenius/dify-plugin-daemon/internal/types/entities" | ||
"github.com/langgenius/dify-plugin-daemon/internal/utils/log" | ||
) | ||
|
||
type PluginLifeTime struct { | ||
lifetime entities.PluginRuntimeTimeLifeInterface | ||
} | ||
|
||
// RegisterPlugin registers a plugin to the cluster, and start to be scheduled | ||
func (c *Cluster) RegisterPlugin(lifetime entities.PluginRuntimeTimeLifeInterface) error { | ||
identity, err := lifetime.Identity() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
lifetime.OnStop(func() { | ||
c.plugin_lock.Lock() | ||
delete(c.plugins, identity) | ||
c.plugin_lock.Unlock() | ||
}) | ||
|
||
c.plugin_lock.Lock() | ||
if !lifetime.Stopped() { | ||
c.plugins[identity] = &PluginLifeTime{ | ||
lifetime: lifetime, | ||
} | ||
} | ||
c.plugin_lock.Unlock() | ||
|
||
log.Info("start to schedule plugin %s", identity) | ||
|
||
return nil | ||
} | ||
|
||
func (c *Cluster) SchedulePlugin(lifetime entities.PluginRuntimeTimeLifeInterface) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.