Skip to content

Commit

Permalink
Scaffold GetTaskListSize method at persistence layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll committed Nov 7, 2023
1 parent d30ab5f commit 2e97487
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 11 deletions.
1 change: 1 addition & 0 deletions common/log/tag/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ var (
StoreOperationUpdateTaskList = storeOperation("update-task-list")
StoreOperationListTaskList = storeOperation("list-task-list")
StoreOperationDeleteTaskList = storeOperation("delete-task-list")
StoreOperationGetTaskListSize = storeOperation("get-task-list-size")
StoreOperationStopTaskList = storeOperation("stop-task-list")

StoreOperationCreateDomain = storeOperation("create-domain")
Expand Down
3 changes: 3 additions & 0 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ const (
PersistenceListTaskListScope
// PersistenceDeleteTaskListScope is the metric scope for persistence.TaskManager.DeleteTaskList API
PersistenceDeleteTaskListScope
// PersistenceGetTaskListSizeScope is the metric scope for persistence.TaskManager.GetTaskListSize API
PersistenceGetTaskListSizeScope
// PersistenceAppendHistoryEventsScope tracks AppendHistoryEvents calls made by service to persistence layer
PersistenceAppendHistoryEventsScope
// PersistenceGetWorkflowExecutionHistoryScope tracks GetWorkflowExecutionHistory calls made by service to persistence layer
Expand Down Expand Up @@ -1339,6 +1341,7 @@ var ScopeDefs = map[ServiceIdx]map[int]scopeDefinition{
PersistenceUpdateTaskListScope: {operation: "UpdateTaskList"},
PersistenceListTaskListScope: {operation: "ListTaskList"},
PersistenceDeleteTaskListScope: {operation: "DeleteTaskList"},
PersistenceGetTaskListSizeScope: {operation: "GetTaskListSize"},
PersistenceAppendHistoryEventsScope: {operation: "AppendHistoryEvents"},
PersistenceGetWorkflowExecutionHistoryScope: {operation: "GetWorkflowExecutionHistory"},
PersistenceDeleteWorkflowExecutionHistoryScope: {operation: "DeleteWorkflowExecutionHistory"},
Expand Down
85 changes: 74 additions & 11 deletions common/mocks/TaskManager.go

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

13 changes: 13 additions & 0 deletions common/persistence/dataManagerInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,18 @@ type (
RangeID int64
}

GetTaskListSizeRequest struct {
DomainID string
DomainName string
TaskListName string
TaskListType int
AckLevel int64
}

GetTaskListSizeResponse struct {
Size int
}

// CreateTasksRequest is used to create a new task for a workflow exectution
CreateTasksRequest struct {
TaskListInfo *TaskListInfo
Expand Down Expand Up @@ -1793,6 +1805,7 @@ type (
UpdateTaskList(ctx context.Context, request *UpdateTaskListRequest) (*UpdateTaskListResponse, error)
ListTaskList(ctx context.Context, request *ListTaskListRequest) (*ListTaskListResponse, error)
DeleteTaskList(ctx context.Context, request *DeleteTaskListRequest) error
GetTaskListSize(ctx context.Context, request *GetTaskListSizeRequest) (*GetTaskListSizeResponse, error)
CreateTasks(ctx context.Context, request *CreateTasksRequest) (*CreateTasksResponse, error)
GetTasks(ctx context.Context, request *GetTasksRequest) (*GetTasksResponse, error)
CompleteTask(ctx context.Context, request *CompleteTaskRequest) error
Expand Down
15 changes: 15 additions & 0 deletions common/persistence/dataManagerInterfaces_mock.go

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

25 changes: 25 additions & 0 deletions common/persistence/persistenceErrorInjectionClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,31 @@ func (p *taskErrorInjectionPersistenceClient) DeleteTaskList(
return persistenceErr
}

func (p *taskErrorInjectionPersistenceClient) GetTaskListSize(
ctx context.Context,
request *GetTaskListSizeRequest,
) (*GetTaskListSizeResponse, error) {
fakeErr := generateFakeError(p.errorRate)

var resp *GetTaskListSizeResponse
var persistenceErr error
var forwardCall bool
if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
resp, persistenceErr = p.persistence.GetTaskListSize(ctx, request)
}

if fakeErr != nil {
p.logger.Error(msgInjectedFakeErr,
tag.StoreOperationGetTaskListSize,
tag.Error(fakeErr),
tag.Bool(forwardCall),
tag.StoreError(persistenceErr),
)
return nil, fakeErr
}
return resp, persistenceErr
}

func (p *taskErrorInjectionPersistenceClient) Close() {
p.persistence.Close()
}
Expand Down
17 changes: 17 additions & 0 deletions common/persistence/persistenceMetricClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,23 @@ func (p *taskPersistenceClient) DeleteTaskList(
return p.call(metrics.PersistenceDeleteTaskListScope, op, metrics.DomainTag(request.DomainName))
}

func (p *taskPersistenceClient) GetTaskListSize(
ctx context.Context,
request *GetTaskListSizeRequest,
) (*GetTaskListSizeResponse, error) {
var resp *GetTaskListSizeResponse
op := func() error {
var err error
resp, err = p.persistence.GetTaskListSize(ctx, request)
return err
}
err := p.call(metrics.PersistenceGetTaskListSizeScope, op)
if err != nil {
return nil, err
}
return resp, nil
}

func (p *taskPersistenceClient) UpdateTaskList(
ctx context.Context,
request *UpdateTaskListRequest,
Expand Down
10 changes: 10 additions & 0 deletions common/persistence/persistenceRateLimitedClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,16 @@ func (p *taskRateLimitedPersistenceClient) DeleteTaskList(
return p.persistence.DeleteTaskList(ctx, request)
}

func (p *taskRateLimitedPersistenceClient) GetTaskListSize(
ctx context.Context,
request *GetTaskListSizeRequest,
) (*GetTaskListSizeResponse, error) {
if ok := p.rateLimiter.Allow(); !ok {
return nil, ErrPersistenceLimitExceeded
}
return p.persistence.GetTaskListSize(ctx, request)
}

func (p *taskRateLimitedPersistenceClient) Close() {
p.persistence.Close()
}
Expand Down
5 changes: 5 additions & 0 deletions common/persistence/taskManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/types"
)

type (
Expand Down Expand Up @@ -69,6 +70,10 @@ func (t *taskManager) DeleteTaskList(ctx context.Context, request *DeleteTaskLis
return t.persistence.DeleteTaskList(ctx, request)
}

func (t *taskManager) GetTaskListSize(ctx context.Context, request *GetTaskListSizeRequest) (*GetTaskListSizeResponse, error) {
return nil, &types.InternalServiceError{Message: "Not yet implemented"}
}

func (t *taskManager) CreateTasks(ctx context.Context, request *CreateTasksRequest) (*CreateTasksResponse, error) {
var internalCreateTasks []*InternalCreateTasksInfo
for _, task := range request.Tasks {
Expand Down

0 comments on commit 2e97487

Please sign in to comment.