Skip to content

Commit

Permalink
use list instead of map to avoid race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
demirkayaender committed Mar 2, 2022
1 parent c18643e commit 8d1f97b
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions service/frontend/adminHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ type (
throttleRetry *backoff.ThrottleRetry
}

workflowQueryTemplate struct {
name string
function func(request *types.AdminMaintainWorkflowRequest) error
}

getWorkflowRawHistoryV2Token struct {
DomainName string
WorkflowID string
Expand Down Expand Up @@ -329,22 +334,28 @@ func (adh *adminHandlerImpl) RemoveTask(

func (adh *adminHandlerImpl) getCorruptWorkflowQueryTemplates(
ctx context.Context, request *types.AdminMaintainWorkflowRequest,
) map[string]func(request *types.AdminMaintainWorkflowRequest) error {
) []workflowQueryTemplate {
client := adh.GetFrontendClient()
return map[string]func(request *types.AdminMaintainWorkflowRequest) error{
"DescribeWorkflowExecution": func(request *types.AdminMaintainWorkflowRequest) error {
_, err := client.DescribeWorkflowExecution(ctx, &types.DescribeWorkflowExecutionRequest{
Domain: request.Domain,
Execution: request.Execution,
})
return err
return []workflowQueryTemplate{
{
name: "DescribeWorkflowExecution",
function: func(request *types.AdminMaintainWorkflowRequest) error {
_, err := client.DescribeWorkflowExecution(ctx, &types.DescribeWorkflowExecutionRequest{
Domain: request.Domain,
Execution: request.Execution,
})
return err
},
},
"GetWorkflowExecutionHistory": func(request *types.AdminMaintainWorkflowRequest) error {
_, err := client.GetWorkflowExecutionHistory(ctx, &types.GetWorkflowExecutionHistoryRequest{
Domain: request.Domain,
Execution: request.Execution,
})
return err
{
name: "GetWorkflowExecutionHistory",
function: func(request *types.AdminMaintainWorkflowRequest) error {
_, err := client.GetWorkflowExecutionHistory(ctx, &types.GetWorkflowExecutionHistoryRequest{
Domain: request.Domain,
Execution: request.Execution,
})
return err
},
},
}
}
Expand Down Expand Up @@ -372,7 +383,9 @@ func (adh *adminHandlerImpl) MaintainCorruptWorkflow(
}

queryTemplates := adh.getCorruptWorkflowQueryTemplates(ctx, request)
for functionName, queryFunc := range queryTemplates {
for _, template := range queryTemplates {
functionName := template.name
queryFunc := template.function
err := queryFunc(request)
if err == nil {
logger.Info(fmt.Sprintf("Query succeeded for function: %s", functionName))
Expand Down

0 comments on commit 8d1f97b

Please sign in to comment.