You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cacah.go 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package services
  2. import (
  3. "fmt"
  4. "time"
  5. "gitlink.org.cn/cloudream/storage-common/globals"
  6. agtmq "gitlink.org.cn/cloudream/storage-common/pkgs/mq/agent"
  7. )
  8. type CacheService struct {
  9. *Service
  10. }
  11. func (svc *Service) CacheSvc() *CacheService {
  12. return &CacheService{Service: svc}
  13. }
  14. func (svc *CacheService) StartCacheMovePackage(userID int64, packageID int64, nodeID int64) (string, error) {
  15. agentCli, err := globals.AgentMQPool.Acquire(nodeID)
  16. if err != nil {
  17. return "", fmt.Errorf("new agent client: %w", err)
  18. }
  19. defer agentCli.Close()
  20. startResp, err := agentCli.StartCacheMovePackage(agtmq.NewStartCacheMovePackage(userID, packageID))
  21. if err != nil {
  22. return "", fmt.Errorf("start cache move package: %w", err)
  23. }
  24. return startResp.TaskID, nil
  25. }
  26. func (svc *CacheService) WaitCacheMovePackage(nodeID int64, taskID string, waitTimeout time.Duration) (bool, error) {
  27. agentCli, err := globals.AgentMQPool.Acquire(nodeID)
  28. if err != nil {
  29. return true, fmt.Errorf("new agent client: %w", err)
  30. }
  31. defer agentCli.Close()
  32. waitResp, err := agentCli.WaitCacheMovePackage(agtmq.NewWaitCacheMovePackage(taskID, waitTimeout.Milliseconds()))
  33. if err != nil {
  34. return true, fmt.Errorf("wait cache move package: %w", err)
  35. }
  36. if !waitResp.IsComplete {
  37. return false, nil
  38. }
  39. if waitResp.Error != "" {
  40. return true, fmt.Errorf("%s", waitResp.Error)
  41. }
  42. return true, nil
  43. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。