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.5 kB

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

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