mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Add Nexus Standalone Describe and Start handlers. - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [x] added new functional test(s) --------- Co-authored-by: Hanzo Dev <[email protected]>
319 lines
12 KiB
Go
319 lines
12 KiB
Go
// Code generated by protoc-gen-go-chasm. DO NOT EDIT.
|
|
package nexusoperationpb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"go.temporal.io/server/client/history"
|
|
"go.temporal.io/server/common"
|
|
"go.temporal.io/server/common/backoff"
|
|
"go.temporal.io/server/common/config"
|
|
"go.temporal.io/server/common/dynamicconfig"
|
|
"go.temporal.io/server/common/headers"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/membership"
|
|
"go.temporal.io/server/common/metrics"
|
|
"go.temporal.io/server/common/primitives"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// NexusOperationServiceLayeredClient is a client for NexusOperationService.
|
|
type NexusOperationServiceLayeredClient struct {
|
|
metricsHandler metrics.Handler
|
|
numShards int32
|
|
redirector history.Redirector[NexusOperationServiceClient]
|
|
retryPolicy backoff.RetryPolicy
|
|
}
|
|
|
|
// NewNexusOperationServiceLayeredClient initializes a new NexusOperationServiceLayeredClient.
|
|
func NewNexusOperationServiceLayeredClient(
|
|
dc *dynamicconfig.Collection,
|
|
rpcFactory common.RPCFactory,
|
|
monitor membership.Monitor,
|
|
config *config.Persistence,
|
|
logger log.Logger,
|
|
metricsHandler metrics.Handler,
|
|
) (NexusOperationServiceClient, error) {
|
|
resolver, err := monitor.GetResolver(primitives.HistoryService)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
connections := history.NewConnectionPool(resolver, rpcFactory, NewNexusOperationServiceClient)
|
|
var redirector history.Redirector[NexusOperationServiceClient]
|
|
if dynamicconfig.HistoryClientOwnershipCachingEnabled.Get(dc)() {
|
|
redirector = history.NewCachingRedirector(
|
|
connections,
|
|
resolver,
|
|
logger,
|
|
dynamicconfig.HistoryClientOwnershipCachingStaleTTL.Get(dc),
|
|
)
|
|
} else {
|
|
redirector = history.NewBasicRedirector(connections, resolver)
|
|
}
|
|
return &NexusOperationServiceLayeredClient{
|
|
metricsHandler: metricsHandler,
|
|
redirector: redirector,
|
|
numShards: config.NumHistoryShards,
|
|
retryPolicy: common.CreateHistoryClientRetryPolicy(),
|
|
}, nil
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) callStartNexusOperationNoRetry(
|
|
ctx context.Context,
|
|
request *StartNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*StartNexusOperationResponse, error) {
|
|
var response *StartNexusOperationResponse
|
|
var err error
|
|
startTime := time.Now().UTC()
|
|
// the caller is a namespace, hence the tag below.
|
|
caller := headers.GetCallerInfo(ctx).CallerName
|
|
metricsHandler := c.metricsHandler.WithTags(
|
|
metrics.OperationTag("NexusOperationService.StartNexusOperation"),
|
|
metrics.NamespaceTag(caller),
|
|
metrics.ServiceRoleTag(metrics.HistoryRoleTagValue),
|
|
)
|
|
metrics.ClientRequests.With(metricsHandler).Record(1)
|
|
defer func() {
|
|
if err != nil {
|
|
metrics.ClientFailures.With(metricsHandler).Record(1, metrics.ServiceErrorTypeTag(err))
|
|
}
|
|
metrics.ClientLatency.With(metricsHandler).Record(time.Since(startTime))
|
|
}()
|
|
shardID := common.WorkflowIDToHistoryShard(request.GetNamespaceId(), request.GetFrontendRequest().GetOperationId(), c.numShards)
|
|
op := func(ctx context.Context, client NexusOperationServiceClient) error {
|
|
var err error
|
|
ctx, cancel := context.WithTimeout(ctx, history.DefaultTimeout)
|
|
defer cancel()
|
|
response, err = client.StartNexusOperation(ctx, request, opts...)
|
|
return err
|
|
}
|
|
err = c.redirector.Execute(ctx, shardID, op)
|
|
return response, err
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) StartNexusOperation(
|
|
ctx context.Context,
|
|
request *StartNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*StartNexusOperationResponse, error) {
|
|
call := func(ctx context.Context) (*StartNexusOperationResponse, error) {
|
|
return c.callStartNexusOperationNoRetry(ctx, request, opts...)
|
|
}
|
|
return backoff.ThrottleRetryContextWithReturn(ctx, call, c.retryPolicy, common.IsServiceClientTransientError)
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) callDescribeNexusOperationNoRetry(
|
|
ctx context.Context,
|
|
request *DescribeNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*DescribeNexusOperationResponse, error) {
|
|
var response *DescribeNexusOperationResponse
|
|
var err error
|
|
startTime := time.Now().UTC()
|
|
// the caller is a namespace, hence the tag below.
|
|
caller := headers.GetCallerInfo(ctx).CallerName
|
|
metricsHandler := c.metricsHandler.WithTags(
|
|
metrics.OperationTag("NexusOperationService.DescribeNexusOperation"),
|
|
metrics.NamespaceTag(caller),
|
|
metrics.ServiceRoleTag(metrics.HistoryRoleTagValue),
|
|
)
|
|
metrics.ClientRequests.With(metricsHandler).Record(1)
|
|
defer func() {
|
|
if err != nil {
|
|
metrics.ClientFailures.With(metricsHandler).Record(1, metrics.ServiceErrorTypeTag(err))
|
|
}
|
|
metrics.ClientLatency.With(metricsHandler).Record(time.Since(startTime))
|
|
}()
|
|
shardID := common.WorkflowIDToHistoryShard(request.GetNamespaceId(), request.GetFrontendRequest().GetOperationId(), c.numShards)
|
|
op := func(ctx context.Context, client NexusOperationServiceClient) error {
|
|
var err error
|
|
ctx, cancel := context.WithTimeout(ctx, history.DefaultTimeout)
|
|
defer cancel()
|
|
response, err = client.DescribeNexusOperation(ctx, request, opts...)
|
|
return err
|
|
}
|
|
err = c.redirector.Execute(ctx, shardID, op)
|
|
return response, err
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) DescribeNexusOperation(
|
|
ctx context.Context,
|
|
request *DescribeNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*DescribeNexusOperationResponse, error) {
|
|
call := func(ctx context.Context) (*DescribeNexusOperationResponse, error) {
|
|
return c.callDescribeNexusOperationNoRetry(ctx, request, opts...)
|
|
}
|
|
return backoff.ThrottleRetryContextWithReturn(ctx, call, c.retryPolicy, common.IsServiceClientTransientError)
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) callRequestCancelNexusOperationNoRetry(
|
|
ctx context.Context,
|
|
request *RequestCancelNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*RequestCancelNexusOperationResponse, error) {
|
|
var response *RequestCancelNexusOperationResponse
|
|
var err error
|
|
startTime := time.Now().UTC()
|
|
// the caller is a namespace, hence the tag below.
|
|
caller := headers.GetCallerInfo(ctx).CallerName
|
|
metricsHandler := c.metricsHandler.WithTags(
|
|
metrics.OperationTag("NexusOperationService.RequestCancelNexusOperation"),
|
|
metrics.NamespaceTag(caller),
|
|
metrics.ServiceRoleTag(metrics.HistoryRoleTagValue),
|
|
)
|
|
metrics.ClientRequests.With(metricsHandler).Record(1)
|
|
defer func() {
|
|
if err != nil {
|
|
metrics.ClientFailures.With(metricsHandler).Record(1, metrics.ServiceErrorTypeTag(err))
|
|
}
|
|
metrics.ClientLatency.With(metricsHandler).Record(time.Since(startTime))
|
|
}()
|
|
shardID := common.WorkflowIDToHistoryShard(request.GetNamespaceId(), request.GetFrontendRequest().GetOperationId(), c.numShards)
|
|
op := func(ctx context.Context, client NexusOperationServiceClient) error {
|
|
var err error
|
|
ctx, cancel := context.WithTimeout(ctx, history.DefaultTimeout)
|
|
defer cancel()
|
|
response, err = client.RequestCancelNexusOperation(ctx, request, opts...)
|
|
return err
|
|
}
|
|
err = c.redirector.Execute(ctx, shardID, op)
|
|
return response, err
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) RequestCancelNexusOperation(
|
|
ctx context.Context,
|
|
request *RequestCancelNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*RequestCancelNexusOperationResponse, error) {
|
|
call := func(ctx context.Context) (*RequestCancelNexusOperationResponse, error) {
|
|
return c.callRequestCancelNexusOperationNoRetry(ctx, request, opts...)
|
|
}
|
|
return backoff.ThrottleRetryContextWithReturn(ctx, call, c.retryPolicy, common.IsServiceClientTransientError)
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) callTerminateNexusOperationNoRetry(
|
|
ctx context.Context,
|
|
request *TerminateNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*TerminateNexusOperationResponse, error) {
|
|
var response *TerminateNexusOperationResponse
|
|
var err error
|
|
startTime := time.Now().UTC()
|
|
// the caller is a namespace, hence the tag below.
|
|
caller := headers.GetCallerInfo(ctx).CallerName
|
|
metricsHandler := c.metricsHandler.WithTags(
|
|
metrics.OperationTag("NexusOperationService.TerminateNexusOperation"),
|
|
metrics.NamespaceTag(caller),
|
|
metrics.ServiceRoleTag(metrics.HistoryRoleTagValue),
|
|
)
|
|
metrics.ClientRequests.With(metricsHandler).Record(1)
|
|
defer func() {
|
|
if err != nil {
|
|
metrics.ClientFailures.With(metricsHandler).Record(1, metrics.ServiceErrorTypeTag(err))
|
|
}
|
|
metrics.ClientLatency.With(metricsHandler).Record(time.Since(startTime))
|
|
}()
|
|
shardID := common.WorkflowIDToHistoryShard(request.GetNamespaceId(), request.GetFrontendRequest().GetOperationId(), c.numShards)
|
|
op := func(ctx context.Context, client NexusOperationServiceClient) error {
|
|
var err error
|
|
ctx, cancel := context.WithTimeout(ctx, history.DefaultTimeout)
|
|
defer cancel()
|
|
response, err = client.TerminateNexusOperation(ctx, request, opts...)
|
|
return err
|
|
}
|
|
err = c.redirector.Execute(ctx, shardID, op)
|
|
return response, err
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) TerminateNexusOperation(
|
|
ctx context.Context,
|
|
request *TerminateNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*TerminateNexusOperationResponse, error) {
|
|
call := func(ctx context.Context) (*TerminateNexusOperationResponse, error) {
|
|
return c.callTerminateNexusOperationNoRetry(ctx, request, opts...)
|
|
}
|
|
return backoff.ThrottleRetryContextWithReturn(ctx, call, c.retryPolicy, common.IsServiceClientTransientError)
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) callDeleteNexusOperationNoRetry(
|
|
ctx context.Context,
|
|
request *DeleteNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*DeleteNexusOperationResponse, error) {
|
|
var response *DeleteNexusOperationResponse
|
|
var err error
|
|
startTime := time.Now().UTC()
|
|
// the caller is a namespace, hence the tag below.
|
|
caller := headers.GetCallerInfo(ctx).CallerName
|
|
metricsHandler := c.metricsHandler.WithTags(
|
|
metrics.OperationTag("NexusOperationService.DeleteNexusOperation"),
|
|
metrics.NamespaceTag(caller),
|
|
metrics.ServiceRoleTag(metrics.HistoryRoleTagValue),
|
|
)
|
|
metrics.ClientRequests.With(metricsHandler).Record(1)
|
|
defer func() {
|
|
if err != nil {
|
|
metrics.ClientFailures.With(metricsHandler).Record(1, metrics.ServiceErrorTypeTag(err))
|
|
}
|
|
metrics.ClientLatency.With(metricsHandler).Record(time.Since(startTime))
|
|
}()
|
|
shardID := common.WorkflowIDToHistoryShard(request.GetNamespaceId(), request.GetFrontendRequest().GetOperationId(), c.numShards)
|
|
op := func(ctx context.Context, client NexusOperationServiceClient) error {
|
|
var err error
|
|
ctx, cancel := context.WithTimeout(ctx, history.DefaultTimeout)
|
|
defer cancel()
|
|
response, err = client.DeleteNexusOperation(ctx, request, opts...)
|
|
return err
|
|
}
|
|
err = c.redirector.Execute(ctx, shardID, op)
|
|
return response, err
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) DeleteNexusOperation(
|
|
ctx context.Context,
|
|
request *DeleteNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*DeleteNexusOperationResponse, error) {
|
|
call := func(ctx context.Context) (*DeleteNexusOperationResponse, error) {
|
|
return c.callDeleteNexusOperationNoRetry(ctx, request, opts...)
|
|
}
|
|
return backoff.ThrottleRetryContextWithReturn(ctx, call, c.retryPolicy, common.IsServiceClientTransientError)
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) callPollNexusOperationNoRetry(
|
|
ctx context.Context,
|
|
request *PollNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*PollNexusOperationResponse, error) {
|
|
var response *PollNexusOperationResponse
|
|
var err error
|
|
startTime := time.Now().UTC()
|
|
// the caller is a namespace, hence the tag below.
|
|
caller := headers.GetCallerInfo(ctx).CallerName
|
|
metricsHandler := c.metricsHandler.WithTags(
|
|
metrics.OperationTag("NexusOperationService.PollNexusOperation"),
|
|
metrics.NamespaceTag(caller),
|
|
metrics.ServiceRoleTag(metrics.HistoryRoleTagValue),
|
|
)
|
|
metrics.ClientRequests.With(metricsHandler).Record(1)
|
|
defer func() {
|
|
if err != nil {
|
|
metrics.ClientFailures.With(metricsHandler).Record(1, metrics.ServiceErrorTypeTag(err))
|
|
}
|
|
metrics.ClientLatency.With(metricsHandler).Record(time.Since(startTime))
|
|
}()
|
|
shardID := common.WorkflowIDToHistoryShard(request.GetNamespaceId(), request.GetFrontendRequest().GetOperationId(), c.numShards)
|
|
op := func(ctx context.Context, client NexusOperationServiceClient) error {
|
|
var err error
|
|
ctx, cancel := context.WithTimeout(ctx, history.DefaultTimeout)
|
|
defer cancel()
|
|
response, err = client.PollNexusOperation(ctx, request, opts...)
|
|
return err
|
|
}
|
|
err = c.redirector.Execute(ctx, shardID, op)
|
|
return response, err
|
|
}
|
|
func (c *NexusOperationServiceLayeredClient) PollNexusOperation(
|
|
ctx context.Context,
|
|
request *PollNexusOperationRequest,
|
|
opts ...grpc.CallOption,
|
|
) (*PollNexusOperationResponse, error) {
|
|
call := func(ctx context.Context) (*PollNexusOperationResponse, error) {
|
|
return c.callPollNexusOperationNoRetry(ctx, request, opts...)
|
|
}
|
|
return backoff.ThrottleRetryContextWithReturn(ctx, call, c.retryPolicy, common.IsServiceClientTransientError)
|
|
}
|