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.

execute_io_plan.go 1.8 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package task
  2. import (
  3. "fmt"
  4. "time"
  5. "gitlink.org.cn/cloudream/common/pkgs/logger"
  6. "gitlink.org.cn/cloudream/common/pkgs/task"
  7. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch"
  8. )
  9. // ExecuteIOPlan 用于执行I/O计划的任务结构体
  10. // 临时使用Task来等待Plan执行进度
  11. type ExecuteIOPlan struct {
  12. PlanID ioswitch.PlanID // 计划ID
  13. Result ioswitch.PlanResult // 执行结果
  14. }
  15. // NewExecuteIOPlan 创建一个新的ExecuteIOPlan实例
  16. // 参数:
  17. //
  18. // planID: 要执行的I/O计划的ID
  19. //
  20. // 返回值:
  21. //
  22. // *ExecuteIOPlan: 新创建的ExecuteIOPlan实例的指针
  23. func NewExecuteIOPlan(planID ioswitch.PlanID) *ExecuteIOPlan {
  24. return &ExecuteIOPlan{
  25. PlanID: planID,
  26. }
  27. }
  28. // Execute 执行I/O计划
  29. // 参数:
  30. //
  31. // task: 任务实例
  32. // ctx: 任务执行上下文
  33. // complete: 完成回调函数
  34. //
  35. // 说明:
  36. //
  37. // 此函数开始执行指定的I/O计划,并通过回调函数报告完成状态
  38. func (t *ExecuteIOPlan) Execute(task *task.Task[TaskContext], ctx TaskContext, complete CompleteFn) {
  39. // 记录任务日志
  40. log := logger.WithType[ExecuteIOPlan]("Task")
  41. log.Debugf("begin with %v", logger.FormatStruct(t))
  42. defer log.Debugf("end") // 确保日志记录任务结束
  43. // 执行I/O计划
  44. ret, err := ctx.sw.ExecutePlan(t.PlanID)
  45. if err != nil {
  46. // 执行计划失败,记录警告日志并调用完成回调函数
  47. err := fmt.Errorf("executing io plan: %w", err)
  48. log.WithField("PlanID", t.PlanID).Warn(err.Error())
  49. complete(err, CompleteOption{
  50. RemovingDelay: time.Minute, // 设置延迟删除选项
  51. })
  52. return
  53. }
  54. // 计划执行成功,更新结果并调用完成回调函数
  55. t.Result = ret
  56. complete(nil, CompleteOption{
  57. RemovingDelay: time.Minute, // 设置延迟删除选项
  58. })
  59. }

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