func (wh *WorkflowHandler) RespondActivityTaskCanceledByID(
	ctx context.Context,
	cancelRequest *types.RespondActivityTaskCanceledByIDRequest,
) (retError error) {
	defer log.CapturePanic(wh.GetLogger(), &retError)

	scope, sw := wh.startRequestProfileWithDomain(ctx, metrics.FrontendRespondActivityTaskCanceledScope, cancelRequest)
	defer sw.Stop()

	if wh.isShuttingDown() {
		return errShuttingDown
	}

	if err := wh.versionChecker.ClientSupported(ctx, wh.config.EnableClientVersionCheck()); err != nil {
		return wh.error(err, scope)
	}

	if cancelRequest == nil {
		return wh.error(errRequestNotSet, scope)
	}

	domainName := cancelRequest.GetDomain()
	tags := getDomainWfIDRunIDTags(domainName, &types.WorkflowExecution{
		WorkflowID: cancelRequest.GetWorkflowID(),
		RunID:      cancelRequest.GetRunID(),
	})

	if domainName == "" {
		return wh.error(errDomainNotSet, scope, tags...)
	}

	// Count the request in the host RPS,
	// but we still accept it even if RPS is exceeded
	wh.allow(false, cancelRequest)

	domainID, err := wh.GetDomainCache().GetDomainID(domainName)
	if err != nil {
		return wh.error(err, scope, tags...)
	}
	workflowID := cancelRequest.GetWorkflowID()
	runID := cancelRequest.GetRunID() // runID is optional so can be empty
	activityID := cancelRequest.GetActivityID()

	if domainID == "" {
		return wh.error(errDomainNotSet, scope, tags...)
	}
	if workflowID == "" {
		return wh.error(errWorkflowIDNotSet, scope, tags...)
	}
	if activityID == "" {
		return wh.error(errActivityIDNotSet, scope, tags...)
	}

	if !common.ValidIDLength(
		cancelRequest.GetIdentity(),
		scope,
		wh.config.MaxIDLengthWarnLimit(),
		wh.config.IdentityMaxLength(cancelRequest.GetDomain()),
		metrics.CadenceErrIdentityExceededWarnLimit,
		domainName,
		wh.GetLogger(),
		tag.IDTypeIdentity) {
		return wh.error(errIdentityTooLong, scope, tags...)
	}

	taskToken := &common.TaskToken{
		DomainID:   domainID,
		RunID:      runID,
		WorkflowID: workflowID,
		ScheduleID: common.EmptyEventID,
		ActivityID: activityID,
	}
	token, err := wh.tokenSerializer.Serialize(taskToken)
	if err != nil {
		return wh.error(err, scope, tags...)
	}

	sizeLimitError := wh.config.BlobSizeLimitError(domainName)
	sizeLimitWarn := wh.config.BlobSizeLimitWarn(domainName)

	if err := common.CheckEventBlobSizeLimit(
		len(cancelRequest.Details),
		sizeLimitWarn,
		sizeLimitError,
		taskToken.DomainID,
		taskToken.WorkflowID,
		taskToken.RunID,
		scope,
		wh.GetThrottledLogger(),
		tag.BlobSizeViolationOperation("RespondActivityTaskCanceledByID"),
	); err != nil {
		// details exceeds blob size limit, we would record it as failure
		failRequest := &types.RespondActivityTaskFailedRequest{
			TaskToken: token,
			Reason:    common.StringPtr(common.FailureReasonCancelDetailsExceedsLimit),
			Details:   cancelRequest.Details[0:sizeLimitError],
			Identity:  cancelRequest.Identity,
		}
		err = wh.GetHistoryClient().RespondActivityTaskFailed(ctx, &types.HistoryRespondActivityTaskFailedRequest{
			DomainUUID:    taskToken.DomainID,
			FailedRequest: failRequest,
		})
		if err != nil {
			return wh.normalizeVersionedErrors(ctx, wh.error(err, scope, tags...))
		}
	} else {
		req := &types.RespondActivityTaskCanceledRequest{
			TaskToken: token,
			Details:   cancelRequest.Details,
			Identity:  cancelRequest.Identity,
		}

		err = wh.GetHistoryClient().RespondActivityTaskCanceled(ctx, &types.HistoryRespondActivityTaskCanceledRequest{
			DomainUUID:    taskToken.DomainID,
			CancelRequest: req,
		})
		if err != nil {
			return wh.normalizeVersionedErrors(ctx, wh.error(err, scope, tags...))
		}
	}

	return nil
}
// RespondActivityTaskCanceledByID - called to cancel an activity task
called to cancel an activity task
// RespondActivityTaskCanceledByID - called to cancel an activity task
func (wh *WorkflowHandler) RespondActivityTaskCanceledByID(
	ctx context.Context,
	cancelRequest *types.RespondActivityTaskCanceledByIDRequest,
) (retError error) {
	defer log.CapturePanic(wh.GetLogger(), &retError)
	scope, sw := wh.startRequestProfileWithDomain(ctx, metrics.FrontendRespondActivityTaskCanceledScope, cancelRequest)
	defer sw.Stop()
	if wh.isShuttingDown() {
		return errShuttingDown
	}
	if err := wh.versionChecker.ClientSupported(ctx, wh.config.EnableClientVersionCheck()); err != nil {
		return wh.error(err, scope)
	}
	if cancelRequest == nil {
		return wh.error(errRequestNotSet, scope)
	}
	domainName := cancelRequest.GetDomain()
	tags := getDomainWfIDRunIDTags(domainName, &types.WorkflowExecution{
		WorkflowID: cancelRequest.GetWorkflowID(),
		RunID:      cancelRequest.GetRunID(),
	})
	if domainName == "" {
		return wh.error(errDomainNotSet, scope, tags...)
	}
	wh.allow(false, cancelRequest)
	domainID, err := wh.GetDomainCache().GetDomainID(domainName)
	if err != nil {
		return wh.error(err, scope, tags...)
	}
	workflowID := cancelRequest.GetWorkflowID()
	runID := cancelRequest.GetRunID() 
	activityID := cancelRequest.GetActivityID()
	if domainID == "" {
		return wh.error(errDomainNotSet, scope, tags...)
	}
	if workflowID == "" {
		return wh.error(errWorkflowIDNotSet, scope, tags...)
	}
	if activityID == "" {
		return wh.error(errActivityIDNotSet, scope, tags...)
	}
	if !common.ValidIDLength(
		cancelRequest.GetIdentity(),
		scope,
		wh.config.MaxIDLengthWarnLimit(),
		wh.config.IdentityMaxLength(cancelRequest.GetDomain()),
		metrics.CadenceErrIdentityExceededWarnLimit,
		domainName,
		wh.GetLogger(),
		tag.IDTypeIdentity) {
		return wh.error(errIdentityTooLong, scope, tags...)
	}
	taskToken := &common.TaskToken{
		DomainID:   domainID,
		RunID:      runID,
		WorkflowID: workflowID,
		ScheduleID: common.EmptyEventID,
		ActivityID: activityID,
	}
	token, err := wh.tokenSerializer.Serialize(taskToken)
	if err != nil {
		return wh.error(err, scope, tags...)
	}
	sizeLimitError := wh.config.BlobSizeLimitError(domainName)
	sizeLimitWarn := wh.config.BlobSizeLimitWarn(domainName)
	if err := common.CheckEventBlobSizeLimit(
		len(cancelRequest.Details),
		sizeLimitWarn,
		sizeLimitError,
		taskToken.DomainID,
		taskToken.WorkflowID,
		taskToken.RunID,
		scope,
		wh.GetThrottledLogger(),
		tag.BlobSizeViolationOperation("RespondActivityTaskCanceledByID"),
	); err != nil {
		failRequest := &types.RespondActivityTaskFailedRequest{
			TaskToken: token,
			Reason:    common.StringPtr(common.FailureReasonCancelDetailsExceedsLimit),
			Details:   cancelRequest.Details[0:sizeLimitError],
			Identity:  cancelRequest.Identity,
		}
		err = wh.GetHistoryClient().RespondActivityTaskFailed(ctx, &types.HistoryRespondActivityTaskFailedRequest{
			DomainUUID:    taskToken.DomainID,
			FailedRequest: failRequest,
		})
		if err != nil {
			return wh.normalizeVersionedErrors(ctx, wh.error(err, scope, tags...))
		}
	} else {
		req := &types.RespondActivityTaskCanceledRequest{
			TaskToken: token,
			Details:   cancelRequest.Details,
			Identity:  cancelRequest.Identity,
		}
		err = wh.GetHistoryClient().RespondActivityTaskCanceled(ctx, &types.HistoryRespondActivityTaskCanceledRequest{
			DomainUUID:    taskToken.DomainID,
			CancelRequest: req,
		})
		if err != nil {
			return wh.normalizeVersionedErrors(ctx, wh.error(err, scope, tags...))
		}
	}
	return nil
}
func ( wh * WorkflowHandler ) RespondActivityTaskCanceledByID ( ctx context . Context , cancelRequest * types . RespondActivityTaskCanceledByIDRequest , ) ( retError error ) { defer log . CapturePanic ( wh . GetLogger ( ) , & retError ) scope , sw := wh . startRequestProfileWithDomain ( ctx , metrics . FrontendRespondActivityTaskCanceledScope , cancelRequest ) defer sw . Stop ( ) if wh . isShuttingDown ( ) { return errShuttingDown } if err := wh . versionChecker . ClientSupported ( ctx , wh . config . EnableClientVersionCheck ( ) ) ; err != nil { return wh . error ( err , scope ) } if cancelRequest == nil { return wh . error ( errRequestNotSet , scope ) } domainName := cancelRequest . GetDomain ( ) tags := getDomainWfIDRunIDTags ( domainName , & types . WorkflowExecution { WorkflowID : cancelRequest . GetWorkflowID ( ) , RunID : cancelRequest . GetRunID ( ) , } ) if domainName == " " { return wh . error ( errDomainNotSet , scope , tags ... ) } wh . allow ( false , cancelRequest ) domainID , err := wh . GetDomainCache ( ) . GetDomainID ( domainName ) if err != nil { return wh . error ( err , scope , tags ... ) } workflowID := cancelRequest . GetWorkflowID ( ) runID := cancelRequest . GetRunID ( ) activityID := cancelRequest . GetActivityID ( ) if domainID == " " { return wh . error ( errDomainNotSet , scope , tags ... ) } if workflowID == " " { return wh . error ( errWorkflowIDNotSet , scope , tags ... ) } if activityID == " " { return wh . error ( errActivityIDNotSet , scope , tags ... ) } if ! common . ValidIDLength ( cancelRequest . GetIdentity ( ) , scope , wh . config . MaxIDLengthWarnLimit ( ) , wh . config . IdentityMaxLength ( cancelRequest . GetDomain ( ) ) , metrics . CadenceErrIdentityExceededWarnLimit , domainName , wh . GetLogger ( ) , tag . IDTypeIdentity ) { return wh . error ( errIdentityTooLong , scope , tags ... ) } taskToken := & common . TaskToken { DomainID : domainID , RunID : runID , WorkflowID : workflowID , ScheduleID : common . EmptyEventID , ActivityID : activityID , } token , err := wh . tokenSerializer . Serialize ( taskToken ) if err != nil { return wh . error ( err , scope , tags ... ) } sizeLimitError := wh . config . BlobSizeLimitError ( domainName ) sizeLimitWarn := wh . config . BlobSizeLimitWarn ( domainName ) if err := common . CheckEventBlobSizeLimit ( len ( cancelRequest . Details ) , sizeLimitWarn , sizeLimitError , taskToken . DomainID , taskToken . WorkflowID , taskToken . RunID , scope , wh . GetThrottledLogger ( ) , tag . BlobSizeViolationOperation ( " " ) , ) ; err != nil { failRequest := & types . RespondActivityTaskFailedRequest { TaskToken : token , Reason : common . StringPtr ( common . FailureReasonCancelDetailsExceedsLimit ) , Details : cancelRequest . Details [ 0 : sizeLimitError ] , Identity : cancelRequest . Identity , } err = wh . GetHistoryClient ( ) . RespondActivityTaskFailed ( ctx , & types . HistoryRespondActivityTaskFailedRequest { DomainUUID : taskToken . DomainID , FailedRequest : failRequest , } ) if err != nil { return wh . normalizeVersionedErrors ( ctx , wh . error ( err , scope , tags ... ) ) } } else { req := & types . RespondActivityTaskCanceledRequest { TaskToken : token , Details : cancelRequest . Details , Identity : cancelRequest . Identity , } err = wh . GetHistoryClient ( ) . RespondActivityTaskCanceled ( ctx , & types . HistoryRespondActivityTaskCanceledRequest { DomainUUID : taskToken . DomainID , CancelRequest : req , } ) if err != nil { return wh . normalizeVersionedErrors ( ctx , wh . error ( err , scope , tags ... ) ) } } return nil }
called to cancel an activity task
called to cancel an activity task
// Count the request in the host RPS, // but we still accept it even if RPS is exceeded // runID is optional so can be empty // details exceeds blob size limit, we would record it as failure