Skip to content

Commit

Permalink
fix/notify: Add deadline for rpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed Apr 27, 2020
1 parent 74eef22 commit e1c6372
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions pkg/notify/rpc/apis/send_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,47 @@

package apis

import "google.golang.org/grpc"
import (
"context"
"time"

"google.golang.org/grpc"
)

type SendNotificationClient struct {
sendAgentClient
Conn *grpc.ClientConn
Conn *grpc.ClientConn
CallTimeout time.Duration
}

func NewSendNotificationClient(cc *grpc.ClientConn) *SendNotificationClient {
return &SendNotificationClient{
sendAgentClient: sendAgentClient{cc},
Conn: cc,
CallTimeout: 30 * time.Second,
}
}

func (c *SendNotificationClient) Send(ctx context.Context, in *SendParams, opts ...grpc.CallOption) (*Empty, error) {
ctx, cancel := context.WithTimeout(ctx, c.CallTimeout)
defer cancel()
return c.sendAgentClient.Send(ctx, in, opts...)
}

func (c *SendNotificationClient) UpdateConfig(ctx context.Context, in *UpdateConfigParams, opts ...grpc.CallOption) (*Empty, error) {
ctx, cancel := context.WithTimeout(ctx, c.CallTimeout)
defer cancel()
return c.sendAgentClient.UpdateConfig(ctx, in, opts...)
}

func (c *SendNotificationClient) ValidateConfig(ctx context.Context, in *UpdateConfigParams, opts ...grpc.CallOption) (*ValidateConfigReply, error) {
ctx, cancel := context.WithTimeout(ctx, c.CallTimeout)
defer cancel()
return c.sendAgentClient.ValidateConfig(ctx, in, opts...)
}

func (c *SendNotificationClient) UseridByMobile(ctx context.Context, in *UseridByMobileParams, opts ...grpc.CallOption) (*UseridByMobileReply, error) {
ctx, cancel := context.WithTimeout(ctx, c.CallTimeout)
defer cancel()
return c.sendAgentClient.UseridByMobile(ctx, in, opts...)
}

0 comments on commit e1c6372

Please sign in to comment.