state.go 909 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package cluster
  2. import (
  3. "github.com/langgenius/dify-plugin-daemon/internal/types/entities"
  4. "github.com/langgenius/dify-plugin-daemon/internal/utils/log"
  5. )
  6. type PluginLifeTime struct {
  7. lifetime entities.PluginRuntimeTimeLifeInterface
  8. }
  9. // RegisterPlugin registers a plugin to the cluster, and start to be scheduled
  10. func (c *Cluster) RegisterPlugin(lifetime entities.PluginRuntimeTimeLifeInterface) error {
  11. identity, err := lifetime.Identity()
  12. if err != nil {
  13. return err
  14. }
  15. lifetime.OnStop(func() {
  16. c.plugin_lock.Lock()
  17. delete(c.plugins, identity)
  18. c.plugin_lock.Unlock()
  19. })
  20. c.plugin_lock.Lock()
  21. if !lifetime.Stopped() {
  22. c.plugins[identity] = &PluginLifeTime{
  23. lifetime: lifetime,
  24. }
  25. }
  26. c.plugin_lock.Unlock()
  27. log.Info("start to schedule plugin %s", identity)
  28. return nil
  29. }
  30. func (c *Cluster) SchedulePlugin(lifetime entities.PluginRuntimeTimeLifeInterface) error {
  31. return nil
  32. }