Skip to content

Commit

Permalink
Merge 6ad31ac into 90a5bdc
Browse files Browse the repository at this point in the history
  • Loading branch information
bishnuag committed Aug 10, 2022
2 parents 90a5bdc + 6ad31ac commit 63f5267
Show file tree
Hide file tree
Showing 66 changed files with 1,623 additions and 459 deletions.
51 changes: 39 additions & 12 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion codegen/templates/http_client.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Client interface {
{{if ne .RequestType "" -}}
args {{.RequestType}},
{{end -}}
timeoutPerAttempt time.Duration,
maxAttempts int,
) (context.Context, {{- if ne .ResponseType "" -}} {{.ResponseType}}, {{- end -}}map[string]string, error)
{{- end -}}
{{- end -}}
Expand Down Expand Up @@ -258,6 +260,8 @@ func (c *{{$clientName}}) {{$methodName}}(
{{if ne .RequestType "" -}}
r {{.RequestType}},
{{end -}}
timeoutPerAttempt time.Duration,
maxAttempts int,
) (context.Context, {{- if ne .ResponseType "" -}} {{.ResponseType}}, {{- end -}}map[string]string, error) {
reqUUID := zanzibar.RequestUUIDFromCtx(ctx)
if headers == nil {
Expand All @@ -273,7 +277,7 @@ func (c *{{$clientName}}) {{$methodName}}(
{{if .ResponseType -}}
var defaultRes {{.ResponseType}}
{{end -}}
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "{{$methodName}}", "{{$serviceMethod}}", c.httpClient)
req := zanzibar.NewClientHTTPRequest(ctx, c.clientID, "{{$methodName}}", "{{$serviceMethod}}", c.httpClient,timeoutPerAttempt,maxAttempts)

{{if .ReqHeaderGoStatements }}
{{range $index, $line := .ReqClientHeaderGoStatements -}}
Expand Down
4 changes: 4 additions & 0 deletions codegen/templates/tchannel_client.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Client interface {
{{if ne .RequestType "" -}}
args {{.RequestType}},
{{end -}}
timeoutPerAttempt time.Duration,
maxAttempts int,
) (context.Context, {{- if ne .ResponseType "" -}} {{.ResponseType}}, {{- end -}}map[string]string, error)
{{- end -}}
{{- end -}}
Expand Down Expand Up @@ -329,6 +331,8 @@ type {{$clientName}} struct {
{{if ne .RequestType "" -}}
args {{.RequestType}},
{{end -}}
timeoutPerAttempt time.Duration,
maxAttempts int,
) (context.Context, {{- if ne .ResponseType "" -}} {{.ResponseType}}, {{- end -}}map[string]string, error) {
var result {{.GenCodePkgName}}.{{title $svc.Name}}_{{title .Name}}_Result
{{if .ResponseType -}}
Expand Down
35 changes: 27 additions & 8 deletions codegen/templates/workflow.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func New{{$workflowInterface}}(deps *module.Dependencies) {{$workflowInterface}}
Clients: deps.Client,
Logger: deps.Default.Logger,
whitelistedDynamicHeaders: whitelistedDynamicHeaders,
defaultDeps: deps.Default,
}
}

Expand All @@ -99,6 +100,7 @@ type {{$workflowStruct}} struct {
Clients *module.ClientDependencies
Logger *zap.Logger
whitelistedDynamicHeaders []string
defaultDeps *zanzibar.DefaultDependencies
}

// Handle calls thrift client.
Expand Down Expand Up @@ -168,40 +170,57 @@ func (w {{$workflowStruct}}) Handle(
}
}

// TODO (bishnu) - timeout and retry will be same as client's unless user overrides with endpoint level timeout
// TODO (bishnu) - endpoint level timeout should be part of config
// TODO (bishnu) - timeout must be configured for client and if available at endpoint level then override it

var timoutPerAttempt time.Duration
var maxRetry int = 1

if w.defaultDeps.Config.ContainsKey("clients.{{$clientID}}.timeoutPerAttempt"){
timoutPerAttempt = time.Duration(w.defaultDeps.Config.MustGetInt("clients.{{$clientID}}.timeoutPerAttempt")) * time.Millisecond
} else if w.defaultDeps.Config.ContainsKey("clients.{{$clientID}}.timeout"){
timoutPerAttempt = time.Duration(w.defaultDeps.Config.MustGetInt("clients.{{$clientID}}.timeout")) * time.Millisecond
}

if w.defaultDeps.Config.ContainsKey("clients.{{$clientID}}.retryCount") {
maxRetry = int(w.defaultDeps.Config.MustGetInt("clients.{{$clientID}}.retryCount"))
}

{{if and (eq $clientReqType "") (eq $clientResType "")}}
{{if (eq (len $resHeaderMap) 0) -}}
ctx, _, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(ctx, clientHeaders)
ctx, _, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(ctx, clientHeaders, timoutPerAttempt, maxRetry)
{{else}}
ctx, cliRespHeaders, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(ctx, clientHeaders)
ctx, cliRespHeaders, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(ctx, clientHeaders, timoutPerAttempt, maxRetry)
{{- end }}
{{else if eq $clientReqType ""}}
{{if (eq (len $resHeaderMap) 0) -}}
ctx, clientRespBody, cliRespHeaders, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(
ctx, clientHeaders,
ctx, clientHeaders, timoutPerAttempt, maxRetry,
)
{{else}}
ctx, clientRespBody, cliRespHeaders, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(
ctx, clientHeaders,
ctx, clientHeaders, timoutPerAttempt, maxRetry,
)
{{- end }}
{{else if eq $clientResType ""}}
{{if (eq (len $resHeaderMap) 0) -}}
ctx, _, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(
ctx, clientHeaders, clientRequest,
ctx, clientHeaders, clientRequest, timoutPerAttempt, maxRetry,
)
{{else}}
ctx, cliRespHeaders, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(
ctx, clientHeaders, clientRequest,
ctx, clientHeaders, clientRequest, timoutPerAttempt, maxRetry,
)
{{- end }}
{{else}}
{{if (eq (len $resHeaderMap) 0) -}}
ctx, clientRespBody, cliRespHeaders, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(
ctx, clientHeaders, clientRequest,
ctx, clientHeaders, clientRequest, timoutPerAttempt, maxRetry,
)
{{else}}
ctx, clientRespBody, cliRespHeaders, err := w.Clients.{{$clientName}}.{{$clientMethodName}}(
ctx, clientHeaders, clientRequest,
ctx, clientHeaders, clientRequest, timoutPerAttempt, maxRetry,
)
{{- end }}
{{end -}}
Expand Down
Loading

0 comments on commit 63f5267

Please sign in to comment.