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.

object.go 1.6 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package mq
  2. import (
  3. "time"
  4. "gitlink.org.cn/cloudream/common/consts/errorcode"
  5. log "gitlink.org.cn/cloudream/common/pkgs/logger"
  6. "gitlink.org.cn/cloudream/common/pkgs/mq"
  7. "gitlink.org.cn/cloudream/storage/agent/internal/task"
  8. agtmq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/agent"
  9. )
  10. func (svc *Service) StartPinningObject(msg *agtmq.StartPinningObject) (*agtmq.StartPinningObjectResp, *mq.CodeMessage) {
  11. log.WithField("FileHash", msg.FileHash).Debugf("pin object")
  12. tsk := svc.taskManager.StartComparable(task.NewIPFSPin(msg.FileHash))
  13. if tsk.Error() != nil {
  14. log.WithField("FileHash", msg.FileHash).
  15. Warnf("pin object failed, err: %s", tsk.Error().Error())
  16. return nil, mq.Failed(errorcode.OperationFailed, "pin object failed")
  17. }
  18. return mq.ReplyOK(agtmq.NewStartPinningObjectResp(tsk.ID()))
  19. }
  20. func (svc *Service) WaitPinningObject(msg *agtmq.WaitPinningObject) (*agtmq.WaitPinningObjectResp, *mq.CodeMessage) {
  21. log.WithField("TaskID", msg.TaskID).Debugf("wait pinning object")
  22. tsk := svc.taskManager.FindByID(msg.TaskID)
  23. if tsk == nil {
  24. return nil, mq.Failed(errorcode.TaskNotFound, "task not found")
  25. }
  26. if msg.WaitTimeoutMs == 0 {
  27. tsk.Wait()
  28. errMsg := ""
  29. if tsk.Error() != nil {
  30. errMsg = tsk.Error().Error()
  31. }
  32. return mq.ReplyOK(agtmq.NewWaitPinningObjectResp(true, errMsg))
  33. } else {
  34. if tsk.WaitTimeout(time.Duration(msg.WaitTimeoutMs)) {
  35. errMsg := ""
  36. if tsk.Error() != nil {
  37. errMsg = tsk.Error().Error()
  38. }
  39. return mq.ReplyOK(agtmq.NewWaitPinningObjectResp(true, errMsg))
  40. }
  41. return mq.ReplyOK(agtmq.NewWaitPinningObjectResp(false, ""))
  42. }
  43. }

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