Skip to content

Commit f3a0866

Browse files
committed

File tree

4 files changed

+54
-23
lines changed

4 files changed

+54
-23
lines changed

polycode/client.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ type StartAppRequest struct {
2828
}
2929

3030
type ExecServiceRequest struct {
31-
Service string `json:"service"`
32-
Method string `json:"method"`
33-
Options TaskOptions `json:"options"`
34-
Input any `json:"input"`
31+
Service string `json:"service"`
32+
TenantId string `json:"tenantId"`
33+
PartitionKey string `json:"partitionKey"`
34+
Method string `json:"method"`
35+
Options TaskOptions `json:"options"`
36+
Input any `json:"input"`
3537
}
3638

3739
type ExecServiceExtendedRequest struct {

polycode/context.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ type ServiceContext interface {
1515
type WorkflowContext interface {
1616
context.Context
1717
AppConfig() AppConfig
18-
Service(service string) (RemoteService, error)
19-
Controller(controller string) (RemoteController, error)
18+
Service(service string) *RemoteServiceBuilder
19+
Controller(controller string) RemoteController
2020
}
2121

2222
type ApiContext interface {
2323
context.Context
2424
AppConfig() AppConfig
25-
Service(service string) (RemoteService, error)
26-
Controller(controller string) (RemoteController, error)
25+
Service(service string) *RemoteServiceBuilder
26+
Controller(controller string) RemoteController
2727
}
2828

2929
type RawContext interface {
@@ -72,12 +72,14 @@ func (s ContextImpl) FileStore() FileStore {
7272
return s.fileStore
7373
}
7474

75-
func (s ContextImpl) Service(service string) (RemoteService, error) {
76-
return RemoteService{ctx: s.ctx, sessionId: s.sessionId, service: service, serviceClient: s.serviceClient}, nil
75+
func (s ContextImpl) Service(service string) *RemoteServiceBuilder {
76+
return &RemoteServiceBuilder{
77+
ctx: s.ctx, sessionId: s.sessionId, service: service, serviceClient: s.serviceClient,
78+
}
7779
}
7880

79-
func (s ContextImpl) Controller(controller string) (RemoteController, error) {
80-
return RemoteController{ctx: s.ctx, sessionId: s.sessionId, controller: controller, serviceClient: s.serviceClient}, nil
81+
func (s ContextImpl) Controller(controller string) RemoteController {
82+
return RemoteController{ctx: s.ctx, sessionId: s.sessionId, controller: controller, serviceClient: s.serviceClient}
8183
}
8284

8385
func (s ContextImpl) ServiceExec(req ExecServiceExtendedRequest) (ExecServiceResponse, error) {

polycode/model.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ type TaskOptions struct {
1515
Retries int `json:"retries"`
1616
RetryOnFail bool `json:"retryOnFail"`
1717
BackoffStrategy BackoffStrategy `json:"backoffStrategy"`
18-
PartitionKey string `json:"partitionKey"`
19-
TenantId string `json:"tenantId"`
20-
}
21-
22-
func (t TaskOptions) WithPartitionKey(partitionKey string) TaskOptions {
23-
t.PartitionKey = partitionKey
24-
return t
2518
}
2619

2720
func (t TaskOptions) WithTimeout(timeout time.Duration) TaskOptions {

polycode/service.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,53 @@ func (r Response) GetAny() (any, error) {
3535
}
3636
}
3737

38+
type RemoteServiceBuilder struct {
39+
ctx context.Context
40+
sessionId string
41+
service string
42+
serviceClient *ServiceClient
43+
tenantId string
44+
partitionKey string
45+
}
46+
47+
func (r *RemoteServiceBuilder) WithTenantId(tenantId string) *RemoteServiceBuilder {
48+
r.tenantId = tenantId
49+
return r
50+
}
51+
52+
func (r *RemoteServiceBuilder) WithPartitionKey(partitionKey string) *RemoteServiceBuilder {
53+
r.partitionKey = partitionKey
54+
return r
55+
}
56+
57+
func (r *RemoteServiceBuilder) Get() RemoteService {
58+
return RemoteService{
59+
ctx: r.ctx,
60+
sessionId: r.sessionId,
61+
service: r.service,
62+
serviceClient: r.serviceClient,
63+
tenantId: r.tenantId,
64+
partitionKey: r.partitionKey,
65+
}
66+
}
67+
3868
type RemoteService struct {
3969
ctx context.Context
4070
sessionId string
4171
service string
4272
serviceClient *ServiceClient
73+
tenantId string
74+
partitionKey string
4375
}
4476

4577
func (r RemoteService) RequestReply(options TaskOptions, method string, input any) Response {
4678
req := ExecServiceRequest{
47-
Service: r.service,
48-
Method: method,
49-
Options: options,
50-
Input: input,
79+
Service: r.service,
80+
TenantId: r.tenantId,
81+
PartitionKey: r.partitionKey,
82+
Method: method,
83+
Options: options,
84+
Input: input,
5185
}
5286

5387
output, err := r.serviceClient.ExecService(r.sessionId, req)

0 commit comments

Comments
 (0)