online.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package gate
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/logger"
  9. "go.uber.org/zap"
  10. "google.golang.org/grpc/status"
  11. pb_v1 "property-device/pb/v1"
  12. "property-device/timetask"
  13. "property-device/utils/gate_utils"
  14. )
  15. //
  16. func GateOnline(ctx context.Context, req *pb_v1.GateOnlineRequest) (reply *pb_v1.GateOnlineReply, err error) {
  17. reply = &pb_v1.GateOnlineReply{}
  18. // 捕获各个task中的异常并返回给调用者
  19. defer func() {
  20. if r := recover(); r != nil {
  21. err = fmt.Errorf("%+v", r)
  22. e := &status.Status{}
  23. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  24. logger.Error("err",
  25. zap.String("system_err", err.Error()),
  26. zap.Stack("stacktrace"))
  27. }
  28. }
  29. }()
  30. timetask.UpdateGateTime(req.Sn, req.Protocol)
  31. if req.Protocol == gate_utils.GateProtocolYufanHttpV1 {
  32. reply.HasTask = gate_utils.HasCommand(req.Sn, req.Protocol)
  33. }
  34. return reply, nil
  35. }