Skip to content

Commit 1882ace

Browse files
committed
Service boilerplate
1 parent b2a7988 commit 1882ace

File tree

16 files changed

+206
-7
lines changed

16 files changed

+206
-7
lines changed

chasm/lib/activity/frontend.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package activity
2+
3+
import (
4+
"context"
5+
6+
"go.temporal.io/api/workflowservice/v1"
7+
"go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1"
8+
)
9+
10+
type FrontendHandler interface {
11+
StartActivityExecution(ctx context.Context, req *workflowservice.StartActivityExecutionRequest) (*workflowservice.StartActivityExecutionResponse, error)
12+
CountActivityExecutions(context.Context, *workflowservice.CountActivityExecutionsRequest) (*workflowservice.CountActivityExecutionsResponse, error)
13+
DeleteActivityExecution(context.Context, *workflowservice.DeleteActivityExecutionRequest) (*workflowservice.DeleteActivityExecutionResponse, error)
14+
DescribeActivityExecution(context.Context, *workflowservice.DescribeActivityExecutionRequest) (*workflowservice.DescribeActivityExecutionResponse, error)
15+
GetActivityResult(context.Context, *workflowservice.GetActivityResultRequest) (*workflowservice.GetActivityResultResponse, error)
16+
ListActivityExecutions(context.Context, *workflowservice.ListActivityExecutionsRequest) (*workflowservice.ListActivityExecutionsResponse, error)
17+
RequestCancelActivityExecution(context.Context, *workflowservice.RequestCancelActivityExecutionRequest) (*workflowservice.RequestCancelActivityExecutionResponse, error)
18+
TerminateActivityExecution(context.Context, *workflowservice.TerminateActivityExecutionRequest) (*workflowservice.TerminateActivityExecutionResponse, error)
19+
}
20+
21+
type frontendHandler struct {
22+
FrontendHandler
23+
client activitypb.ActivityServiceClient
24+
}
25+
26+
func NewFrontendHandler(client activitypb.ActivityServiceClient) FrontendHandler {
27+
return &frontendHandler{
28+
client: client,
29+
}
30+
}
31+
32+
func (h *frontendHandler) StartActivityExecution(ctx context.Context, req *workflowservice.StartActivityExecutionRequest) (*workflowservice.StartActivityExecutionResponse, error) {
33+
resp, err := h.client.StartActivityExecution(ctx, &activitypb.StartActivityExecutionRequest{
34+
// NamespaceId
35+
FrontendRequest: req,
36+
})
37+
return resp.GetFrontendResponse(), err
38+
}

chasm/lib/activity/fx.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package activity
2+
3+
import (
4+
"go.temporal.io/server/chasm"
5+
"go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1"
6+
"go.uber.org/fx"
7+
)
8+
9+
var HistoryModule = fx.Module(
10+
"activity-history",
11+
fx.Provide(
12+
newHandler,
13+
newLibrary,
14+
),
15+
fx.Invoke(func(l *library, registry *chasm.Registry) {
16+
registry.Register(l)
17+
}),
18+
)
19+
20+
var FrontendModule = fx.Module(
21+
"activity-frontend",
22+
fx.Provide(activitypb.NewActivityServiceLayeredClient),
23+
fx.Provide(NewFrontendHandler),
24+
)

chasm/lib/activity/gen/activitypb/v1/service_client.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chasm/lib/activity/handler.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package activity
2+
3+
import (
4+
"context"
5+
6+
"go.temporal.io/api/workflowservice/v1"
7+
"go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1"
8+
)
9+
10+
type handler struct {
11+
activitypb.UnimplementedActivityServiceServer
12+
}
13+
14+
func newHandler() *handler {
15+
return &handler{}
16+
}
17+
18+
func (h *handler) StartActivityExecution(ctx context.Context, req *activitypb.StartActivityExecutionRequest) (*activitypb.StartActivityExecutionResponse, error) {
19+
return &activitypb.StartActivityExecutionResponse{
20+
FrontendResponse: &workflowservice.StartActivityExecutionResponse{
21+
// TODO
22+
},
23+
}, nil
24+
}

chasm/lib/activity/library.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package activity
2+
3+
import (
4+
"go.temporal.io/server/chasm"
5+
"go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1"
6+
"google.golang.org/grpc"
7+
)
8+
9+
type library struct {
10+
chasm.UnimplementedLibrary
11+
handler *handler
12+
}
13+
14+
func newLibrary(*handler) *library {
15+
return &library{}
16+
}
17+
18+
func (l *library) Name() string {
19+
return "activity"
20+
}
21+
22+
func (l *library) RegisterServices(server *grpc.Server) {
23+
server.RegisterService(&activitypb.ActivityService_ServiceDesc, l.handler)
24+
}

chasm/lib/tests/gen/testspb/v1/service_client.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tools/protoc-gen-go-chasm/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (p *Plugin) genClient(w *writer, svc *protogen.Service) error {
192192

193193
ctorName := fmt.Sprintf("New%s", structName)
194194
w.println("// %s initializes a new %s.", ctorName, structName)
195-
w.println("func New%s(", ctorName)
195+
w.println("func %s(", ctorName)
196196
w.indent()
197197
w.println("dc *dynamicconfig.Collection,")
198198
w.println("rpcFactory common.RPCFactory,")
@@ -201,7 +201,7 @@ func (p *Plugin) genClient(w *writer, svc *protogen.Service) error {
201201
w.println("logger log.Logger,")
202202
w.println("metricsHandler metrics.Handler,")
203203
w.unindent()
204-
w.println(") (*%s, error) {", structName)
204+
w.println(") (%sClient, error) {", svc.GoName)
205205
w.indent() // start ctor body
206206
w.println("resolver, err := monitor.GetResolver(primitives.HistoryService)")
207207
w.println("if err != nil {")

common/rpc/interceptor/redirection.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ var (
135135
"UpdateTaskQueueConfig": func() any { return &workflowservice.UpdateTaskQueueConfigResponse{} },
136136
"FetchWorkerConfig": func() any { return &workflowservice.FetchWorkerConfigResponse{} },
137137
"UpdateWorkerConfig": func() any { return &workflowservice.UpdateWorkerConfigResponse{} },
138+
139+
"StartActivityExecution": func() any { return &workflowservice.StartActivityExecutionResponse{} },
140+
"CountActivityExecutions": func() any { return &workflowservice.CountActivityExecutionsResponse{} },
141+
"ListActivityExecutions": func() any { return &workflowservice.ListActivityExecutionsResponse{} },
142+
"DescribeActivityExecution": func() any { return &workflowservice.DescribeActivityExecutionResponse{} },
143+
"GetActivityResult": func() any { return &workflowservice.GetActivityResultResponse{} },
144+
"RequestCancelActivityExecution": func() any { return &workflowservice.RequestCancelActivityExecutionResponse{} },
145+
"TerminateActivityExecution": func() any { return &workflowservice.TerminateActivityExecutionResponse{} },
146+
"DeleteActivityExecution": func() any { return &workflowservice.DeleteActivityExecutionResponse{} },
138147
}
139148
)
140149

common/rpc/interceptor/redirection_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ func (s *redirectionInterceptorSuite) TestGlobalAPI() {
190190
"UpdateTaskQueueConfig": {},
191191
"FetchWorkerConfig": {},
192192
"UpdateWorkerConfig": {},
193+
194+
"StartActivityExecution": {},
195+
"CountActivityExecutions": {},
196+
"ListActivityExecutions": {},
197+
"DescribeActivityExecution": {},
198+
"GetActivityResult": {},
199+
"RequestCancelActivityExecution": {},
200+
"TerminateActivityExecution": {},
201+
"DeleteActivityExecution": {},
193202
}, apis)
194203
}
195204

service/frontend/configs/quotas.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ var (
4242
"/temporal.api.workflowservice.v1.WorkflowService/UpdateWorkflowExecution": 1,
4343
"/temporal.api.workflowservice.v1.WorkflowService/GetWorkflowExecutionHistory": 1,
4444
"/temporal.api.workflowservice.v1.WorkflowService/PollNexusTaskQueue": 1,
45+
// TODO: Map to PollActivityResult if request is long-polling
46+
"/temporal.api.workflowservice.v1.WorkflowService/GetActivityResult": 1,
4547

4648
// potentially long-running, depending on the operations
4749
"/temporal.api.workflowservice.v1.WorkflowService/ExecuteMultiOperation": 1,
@@ -71,6 +73,7 @@ var (
7173
"/temporal.api.workflowservice.v1.WorkflowService/ExecuteMultiOperation": 1,
7274
"/temporal.api.workflowservice.v1.WorkflowService/CreateSchedule": 1,
7375
"/temporal.api.workflowservice.v1.WorkflowService/StartBatchOperation": 1,
76+
"/temporal.api.workflowservice.v1.WorkflowService/StartActivityExecution": 1,
7477
DispatchNexusTaskByNamespaceAndTaskQueueAPIName: 1,
7578
DispatchNexusTaskByEndpointAPIName: 1,
7679

@@ -114,6 +117,10 @@ var (
114117
"/temporal.api.workflowservice.v1.WorkflowService/ListWorkflowRules": 2,
115118
"/temporal.api.workflowservice.v1.WorkflowService/TriggerWorkflowRule": 2,
116119
"/temporal.api.workflowservice.v1.WorkflowService/UpdateTaskQueueConfig": 2,
120+
"/temporal.api.workflowservice.v1.WorkflowService/RequestCancelActivityExecution": 2,
121+
"/temporal.api.workflowservice.v1.WorkflowService/TerminateActivityExecution": 2,
122+
"/temporal.api.workflowservice.v1.WorkflowService/DeleteActivityExecution": 2,
123+
"/temporal.api.workflowservice.v1.WorkflowService/GetActivityResult": 2,
117124

118125
// P3: Status Querying APIs
119126
"/temporal.api.workflowservice.v1.WorkflowService/DescribeWorkflowExecution": 3,
@@ -130,6 +137,7 @@ var (
130137
"/temporal.api.workflowservice.v1.WorkflowService/DescribeWorkerDeploymentVersion": 3,
131138
"/temporal.api.workflowservice.v1.WorkflowService/DescribeWorkerDeployment": 3,
132139
"/temporal.api.workflowservice.v1.WorkflowService/ListWorkerDeployments": 3,
140+
"/temporal.api.workflowservice.v1.WorkflowService/DescribeActivityExecution": 3,
133141

134142
// P3: Progress APIs for reporting cancellations and failures.
135143
// They are relatively low priority as the tasks need to be retried anyway.
@@ -171,6 +179,8 @@ var (
171179
"/temporal.api.workflowservice.v1.WorkflowService/ListArchivedWorkflowExecutions": 1,
172180
"/temporal.api.workflowservice.v1.WorkflowService/ListWorkers": 1,
173181
"/temporal.api.workflowservice.v1.WorkflowService/DescribeWorker": 1,
182+
"/temporal.api.workflowservice.v1.WorkflowService/CountActivityExecutions": 1,
183+
"/temporal.api.workflowservice.v1.WorkflowService/ListActivityExecutions": 1,
174184

175185
// APIs that rely on visibility
176186
"/temporal.api.workflowservice.v1.WorkflowService/GetWorkerTaskReachability": 1,

0 commit comments

Comments
 (0)