task.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2022 gorse Project Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package protocol
  15. import (
  16. "time"
  17. "github.com/zhenghaoz/gorse/base/progress"
  18. )
  19. //go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative protocol.proto
  20. func DecodeProgress(in *PushProgressRequest) []progress.Progress {
  21. var progressList []progress.Progress
  22. for _, p := range in.Progress {
  23. progressList = append(progressList, progress.Progress{
  24. Tracer: p.GetTracer(),
  25. Name: p.GetName(),
  26. Status: progress.Status(p.GetStatus()),
  27. Count: int(p.GetCount()),
  28. Total: int(p.GetTotal()),
  29. StartTime: time.UnixMilli(p.GetStartTime()),
  30. FinishTime: time.UnixMilli(p.GetFinishTime()),
  31. })
  32. }
  33. return progressList
  34. }
  35. func EncodeProgress(progressList []progress.Progress) *PushProgressRequest {
  36. var pbList []*Progress
  37. for _, p := range progressList {
  38. pbList = append(pbList, &Progress{
  39. Tracer: p.Tracer,
  40. Name: p.Name,
  41. Status: string(p.Status),
  42. Count: int64(p.Count),
  43. Total: int64(p.Total),
  44. StartTime: p.StartTime.UnixMilli(),
  45. FinishTime: p.FinishTime.UnixMilli(),
  46. })
  47. }
  48. return &PushProgressRequest{
  49. Progress: pbList,
  50. }
  51. }