server.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package grpc
  2. import (
  3. "context"
  4. v1 "go-common/app/interface/main/creative/api"
  5. newcMdl "go-common/app/interface/main/creative/model/newcomer"
  6. "go-common/app/interface/main/creative/service/archive"
  7. "go-common/app/interface/main/creative/service/newcomer"
  8. "go-common/library/net/rpc/warden"
  9. )
  10. // New boradcast grpc server.
  11. func New(cfg *warden.ServerConfig, asrv *archive.Service, nsrv *newcomer.Service) (ws *warden.Server) {
  12. ws = warden.NewServer(cfg)
  13. v1.RegisterCreativeServer(ws.Server(), &server{asrv, nsrv})
  14. var err error
  15. if ws, err = ws.Start(); err != nil {
  16. panic(err)
  17. }
  18. return
  19. }
  20. type server struct {
  21. asrv *archive.Service
  22. nsrv *newcomer.Service
  23. }
  24. // Ping Service
  25. func (s *server) Ping(ctx context.Context, req *v1.Empty) (*v1.Empty, error) {
  26. return &v1.Empty{}, nil
  27. }
  28. // Close Service
  29. func (s *server) Close(ctx context.Context, req *v1.Empty) (*v1.Empty, error) {
  30. // TODO: some graceful close
  31. return &v1.Empty{}, nil
  32. }
  33. // AddReport .
  34. func (s *server) CheckTaskState(c context.Context, arg *v1.TaskRequest) (res *v1.TaskReply, err error) {
  35. req := &newcMdl.CheckTaskStateReq{
  36. MID: arg.Mid,
  37. TaskID: arg.TaskId,
  38. }
  39. return &v1.TaskReply{FinishState: s.nsrv.CheckTaskState(c, req)}, nil
  40. }
  41. // FlowJudge .
  42. func (s *server) FlowJudge(c context.Context, arg *v1.FlowRequest) (res *v1.FlowResponse, err error) {
  43. res = new(v1.FlowResponse)
  44. a, err := s.asrv.FlowJudge(c, arg.Business, arg.Gid, arg.Oids)
  45. if err != nil {
  46. return
  47. }
  48. res.Oids = a
  49. return
  50. }