gc.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package cluster
  2. import (
  3. "errors"
  4. "time"
  5. "github.com/langgenius/dify-plugin-daemon/internal/utils/cache"
  6. )
  7. // gc the nodes has already deactivated
  8. func (c *Cluster) gcNodes() error {
  9. var total_errors error
  10. add_error := func(err error) {
  11. if err != nil {
  12. if total_errors == nil {
  13. total_errors = err
  14. } else {
  15. total_errors = errors.Join(total_errors, err)
  16. }
  17. }
  18. }
  19. // get all nodes status
  20. nodes, err := cache.GetMap[node](CLUSTER_STATUS_HASH_MAP_KEY)
  21. if err == cache.ErrNotFound {
  22. return nil
  23. }
  24. for node_id, node_status := range nodes {
  25. // delete the node if it is disconnected
  26. if time.Since(time.Unix(node_status.LastPingAt, 0)) > NODE_DISCONNECTED_TIMEOUT {
  27. // gc the node
  28. if err := c.gcNode(node_id); err != nil {
  29. add_error(err)
  30. continue
  31. }
  32. // delete the node status
  33. if err := cache.DelMapField(CLUSTER_STATUS_HASH_MAP_KEY, node_id); err != nil {
  34. add_error(err)
  35. }
  36. }
  37. }
  38. return total_errors
  39. }
  40. // remove the resource associated with the node
  41. func (c *Cluster) gcNode(node_id string) error {
  42. return nil
  43. }