Skip to content

Commit 4c80354

Browse files
author
Christopher Ludden
committed
fix: fixes example, justfile, updates README
1 parent 76d9822 commit 4c80354

File tree

6 files changed

+110
-56
lines changed

6 files changed

+110
-56
lines changed

README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,22 @@ service Mutex {
108108
// ##########################################################################
109109
110110
// AcquireLease enqueues a lease on the given resource
111-
rpc AcquireLease(AcquireLeaseSignal) returns (google.protobuf.Empty) {
111+
rpc AcquireLease(AcquireLeaseRequest) returns (google.protobuf.Empty) {
112112
option (temporal.v1.signal) = {};
113113
}
114114
115-
// LeaseAcquired enqueues a lease on the given resource
116-
rpc LeaseAcquired(LeaseAcquiredSignal) returns (google.protobuf.Empty) {
115+
// LeaseAcquired notifies the calling workflow that a lease has been required
116+
rpc LeaseAcquired(LeaseAcquiredRequest) returns (google.protobuf.Empty) {
117117
option (temporal.v1.signal) = {};
118118
}
119119
120-
// RenewLease enqueues a lease on the given resource
121-
rpc RenewLease(RenewLeaseSignal) returns (google.protobuf.Empty) {
120+
// RenewLease extends the validity of an existing lease
121+
rpc RenewLease(RenewLeaseRequest) returns (google.protobuf.Empty) {
122122
option (temporal.v1.signal) = {};
123123
}
124124
125-
// RevokeLease enqueues a lease on the given resource
126-
rpc RevokeLease(RevokeLeaseSignal) returns (google.protobuf.Empty) {
125+
// RevokeLease revokes an existing lease
126+
rpc RevokeLease(RevokeLeaseRequest) returns (google.protobuf.Empty) {
127127
option (temporal.v1.signal) = {};
128128
}
129129
}
@@ -132,14 +132,19 @@ service Mutex {
132132
// Workflow Messages
133133
// ############################################################################
134134
135+
// MutexRequest describes the input to a Mutex workflow/activity
135136
message MutexRequest {
136137
string resource = 1;
137138
}
138139
140+
// SampleWorkflowWithMutexRequest describes the input to a SampleWorkflowWithMutex workflow
139141
message SampleWorkflowWithMutexRequest {
140142
string resource = 1;
143+
string dest = 2;
144+
double amount = 3;
141145
}
142146
147+
// SampleWorkflowWithMutexResponse describes the output from a SampleWorkflowWithMutex workflow
143148
message SampleWorkflowWithMutexResponse {
144149
string result = 1;
145150
}
@@ -148,23 +153,27 @@ message SampleWorkflowWithMutexResponse {
148153
// Signal Messages
149154
// ############################################################################
150155
151-
message AcquireLeaseSignal {
156+
// AcquireLeaseRequest describes the input to a AcquireLease signal
157+
message AcquireLeaseRequest {
152158
string workflow_id = 1;
153159
google.protobuf.Duration timeout = 2;
154160
}
155161
156-
message LeaseAcquiredSignal {
162+
// LeaseAcquiredRequest describes the input to a LeaseAcquired signal
163+
message LeaseAcquiredRequest {
157164
string workflow_id = 1;
158165
string run_id = 2;
159166
string lease_id = 3;
160167
}
161168
162-
message RenewLeaseSignal {
169+
// RenewLeaseRequest describes the input to a RenewLease signal
170+
message RenewLeaseRequest {
163171
string lease_id = 1;
164172
google.protobuf.Duration timeout = 2;
165173
}
166174
167-
message RevokeLeaseSignal {
175+
// RevokeLeaseRequest describes the input to a RevokeLease signal
176+
message RevokeLeaseRequest {
168177
string lease_id = 1;
169178
}
170179
```
@@ -176,7 +185,7 @@ buf generate
176185

177186
8. Implement your activities, workflows, and worker, for general usage see [example](./example) for a sample inspired by [temporalio/samples-go/mutex](https://github.com/temporalio/samples-go/tree/main/mutex)
178187
```go
179-
package mutex
188+
package main
180189
181190
import (
182191
"context"
@@ -186,14 +195,28 @@ import (
186195
"github.com/cludden/protoc-gen-go-temporal/example/mutexv1"
187196
"github.com/google/uuid"
188197
"go.temporal.io/sdk/activity"
198+
"go.temporal.io/sdk/client"
189199
"go.temporal.io/sdk/log"
190200
"go.temporal.io/sdk/workflow"
201+
"go.temporal.io/sdk/worker"
191202
"google.golang.org/protobuf/types/known/durationpb"
192203
)
193204
194-
// Workflows manages shared state for workflow constructors
205+
func main() {
206+
c, _ := client.Dial(client.Options{})
207+
defer c.Close()
208+
209+
w := worker.New(c, mutexv1.MutexTaskQueue, worker.Options{})
210+
mutexv1.RegisterActivities(w, &mutex.Activites{Client: mutexv1.NewClient(c)})
211+
mutexv1.RegisterWorkflows(w, &mutex.Workflows{})
212+
w.Run(worker.InterruptCh())
213+
}
214+
215+
// Workflows manages shared state for workflow constructors, local activities, side effects
195216
type Workflows struct{}
196217
218+
// ============================================================================
219+
197220
// MutexWorkflow provides a mutex over a shared resource
198221
type MutexWorkflow struct {
199222
*mutexv1.MutexInput
@@ -267,6 +290,8 @@ func (wf *MutexWorkflow) Execute(ctx workflow.Context) error {
267290
}
268291
}
269292
293+
// ============================================================================
294+
270295
// SampleWorkflowWithMutexWorkflow simulates a long running workflow requiring exclusive access to a shared resource
271296
type SampleWorkflowWithMutexWorkflow struct {
272297
*mutexv1.SampleWorkflowWithMutexInput
@@ -310,6 +335,8 @@ func (wf *SampleWorkflowWithMutexWorkflow) Execute(ctx workflow.Context) (resp *
310335
return &mutexv1.SampleWorkflowWithMutexResponse{Result: lease.GetLeaseId()}, nil
311336
}
312337
338+
// ============================================================================
339+
313340
// Activities manages shared state for activities
314341
type Activites struct {
315342
Client mutexv1.Client

example/mutexv1/example.pb.go

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

example/mutexv1/example.proto

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ service Mutex {
5353
option (temporal.v1.signal) = {};
5454
}
5555

56-
// LeaseAcquired enqueues a lease on the given resource
56+
// LeaseAcquired notifies the calling workflow that a lease has been required
5757
rpc LeaseAcquired(LeaseAcquiredRequest) returns (google.protobuf.Empty) {
5858
option (temporal.v1.signal) = {};
5959
}
6060

61-
// RenewLease enqueues a lease on the given resource
61+
// RenewLease extends the validity of an existing lease
6262
rpc RenewLease(RenewLeaseRequest) returns (google.protobuf.Empty) {
6363
option (temporal.v1.signal) = {};
6464
}
6565

66-
// RevokeLease enqueues a lease on the given resource
66+
// RevokeLease revokes an existing lease
6767
rpc RevokeLease(RevokeLeaseRequest) returns (google.protobuf.Empty) {
6868
option (temporal.v1.signal) = {};
6969
}
@@ -73,16 +73,19 @@ service Mutex {
7373
// Workflow Messages
7474
// ############################################################################
7575

76+
// MutexRequest describes the input to a Mutex workflow/activity
7677
message MutexRequest {
7778
string resource = 1;
7879
}
7980

81+
// SampleWorkflowWithMutexRequest describes the input to a SampleWorkflowWithMutex workflow
8082
message SampleWorkflowWithMutexRequest {
8183
string resource = 1;
8284
string dest = 2;
8385
double amount = 3;
8486
}
8587

88+
// SampleWorkflowWithMutexResponse describes the output from a SampleWorkflowWithMutex workflow
8689
message SampleWorkflowWithMutexResponse {
8790
string result = 1;
8891
}
@@ -91,22 +94,26 @@ message SampleWorkflowWithMutexResponse {
9194
// Signal Messages
9295
// ############################################################################
9396

97+
// AcquireLeaseRequest describes the input to a AcquireLease signal
9498
message AcquireLeaseRequest {
9599
string workflow_id = 1;
96100
google.protobuf.Duration timeout = 2;
97101
}
98102

103+
// LeaseAcquiredRequest describes the input to a LeaseAcquired signal
99104
message LeaseAcquiredRequest {
100105
string workflow_id = 1;
101106
string run_id = 2;
102107
string lease_id = 3;
103108
}
104109

110+
// RenewLeaseRequest describes the input to a RenewLease signal
105111
message RenewLeaseRequest {
106112
string lease_id = 1;
107113
google.protobuf.Duration timeout = 2;
108114
}
109115

116+
// RevokeLeaseRequest describes the input to a RevokeLease signal
110117
message RevokeLeaseRequest {
111118
string lease_id = 1;
112119
}

example/mutexv1/example_temporal.pb.go

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

0 commit comments

Comments
 (0)