diff --git a/examples/codegen/main.go b/examples/codegen/main.go index 757a4eb..a558145 100644 --- a/examples/codegen/main.go +++ b/examples/codegen/main.go @@ -118,10 +118,37 @@ func (c counter) Watch(ctx restate.ObjectSharedContext, req *helloworld.WatchReq return &helloworld.GetResponse{Value: next}, nil } +type workflow struct { + helloworld.UnimplementedWorkflowServer +} + +func (workflow) Run(ctx restate.WorkflowContext, _ *helloworld.RunRequest) (*helloworld.RunResponse, error) { + restate.Set(ctx, "status", "waiting") + _, err := restate.Promise[restate.Void](ctx, "promise").Result() + if err != nil { + return nil, err + } + restate.Set(ctx, "status", "finished") + return &helloworld.RunResponse{Status: "finished"}, nil +} + +func (workflow) Finish(ctx restate.WorkflowSharedContext, _ *helloworld.FinishRequest) (*helloworld.FinishResponse, error) { + return nil, restate.Promise[restate.Void](ctx, "promise").Resolve(restate.Void{}) +} + +func (workflow) Status(ctx restate.WorkflowSharedContext, _ *helloworld.StatusRequest) (*helloworld.StatusResponse, error) { + status, err := restate.Get[string](ctx, "status") + if err != nil { + return nil, err + } + return &helloworld.StatusResponse{Status: status}, nil +} + func main() { server := server.NewRestate(). Bind(helloworld.NewGreeterServer(greeter{})). - Bind(helloworld.NewCounterServer(counter{})) + Bind(helloworld.NewCounterServer(counter{})). + Bind(helloworld.NewWorkflowServer(workflow{})) if err := server.Start(context.Background(), ":9080"); err != nil { slog.Error("application exited unexpectedly", "err", err.Error()) diff --git a/examples/codegen/proto/helloworld.pb.go b/examples/codegen/proto/helloworld.pb.go index c1e7b34..8139585 100644 --- a/examples/codegen/proto/helloworld.pb.go +++ b/examples/codegen/proto/helloworld.pb.go @@ -379,6 +379,252 @@ func (x *WatchRequest) GetTimeoutMillis() int64 { return 0 } +type RunRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *RunRequest) Reset() { + *x = RunRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_helloworld_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RunRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RunRequest) ProtoMessage() {} + +func (x *RunRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_helloworld_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RunRequest.ProtoReflect.Descriptor instead. +func (*RunRequest) Descriptor() ([]byte, []int) { + return file_proto_helloworld_proto_rawDescGZIP(), []int{8} +} + +type RunResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` +} + +func (x *RunResponse) Reset() { + *x = RunResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_helloworld_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RunResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RunResponse) ProtoMessage() {} + +func (x *RunResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_helloworld_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RunResponse.ProtoReflect.Descriptor instead. +func (*RunResponse) Descriptor() ([]byte, []int) { + return file_proto_helloworld_proto_rawDescGZIP(), []int{9} +} + +func (x *RunResponse) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +type StatusRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *StatusRequest) Reset() { + *x = StatusRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_helloworld_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatusRequest) ProtoMessage() {} + +func (x *StatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_helloworld_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatusRequest.ProtoReflect.Descriptor instead. +func (*StatusRequest) Descriptor() ([]byte, []int) { + return file_proto_helloworld_proto_rawDescGZIP(), []int{10} +} + +type StatusResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` +} + +func (x *StatusResponse) Reset() { + *x = StatusResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_helloworld_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatusResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatusResponse) ProtoMessage() {} + +func (x *StatusResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_helloworld_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatusResponse.ProtoReflect.Descriptor instead. +func (*StatusResponse) Descriptor() ([]byte, []int) { + return file_proto_helloworld_proto_rawDescGZIP(), []int{11} +} + +func (x *StatusResponse) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +type FinishRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *FinishRequest) Reset() { + *x = FinishRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_helloworld_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FinishRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FinishRequest) ProtoMessage() {} + +func (x *FinishRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_helloworld_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FinishRequest.ProtoReflect.Descriptor instead. +func (*FinishRequest) Descriptor() ([]byte, []int) { + return file_proto_helloworld_proto_rawDescGZIP(), []int{12} +} + +type FinishResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *FinishResponse) Reset() { + *x = FinishResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_helloworld_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FinishResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FinishResponse) ProtoMessage() {} + +func (x *FinishResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_helloworld_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FinishResponse.ProtoReflect.Descriptor instead. +func (*FinishResponse) Descriptor() ([]byte, []int) { + return file_proto_helloworld_proto_rawDescGZIP(), []int{13} +} + var File_proto_helloworld_proto protoreflect.FileDescriptor var file_proto_helloworld_proto_rawDesc = []byte{ @@ -404,40 +650,63 @@ var file_proto_helloworld_proto_rawDesc = []byte{ 0x73, 0x65, 0x22, 0x35, 0x0a, 0x0c, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x5f, 0x6d, 0x69, 0x6c, 0x6c, 0x69, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x74, 0x69, 0x6d, 0x65, - 0x6f, 0x75, 0x74, 0x4d, 0x69, 0x6c, 0x6c, 0x69, 0x73, 0x32, 0x4c, 0x0a, 0x07, 0x47, 0x72, 0x65, - 0x65, 0x74, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, - 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, - 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x68, 0x65, 0x6c, - 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x32, 0x98, 0x02, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, - 0x74, 0x65, 0x72, 0x12, 0x38, 0x0a, 0x03, 0x41, 0x64, 0x64, 0x12, 0x16, 0x2e, 0x68, 0x65, 0x6c, - 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, - 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3c, 0x0a, - 0x03, 0x47, 0x65, 0x74, 0x12, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, - 0x64, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x68, - 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x04, 0x98, 0x80, 0x01, 0x02, 0x12, 0x4d, 0x0a, 0x0a, 0x41, - 0x64, 0x64, 0x57, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x12, 0x1d, 0x2e, 0x68, 0x65, 0x6c, 0x6c, - 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x41, 0x64, 0x64, 0x57, 0x61, 0x74, 0x63, 0x68, 0x65, - 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, - 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x41, 0x64, 0x64, 0x57, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x05, 0x57, 0x61, - 0x74, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, - 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, - 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x04, 0x98, 0x80, 0x01, 0x02, 0x1a, 0x04, 0x98, 0x80, - 0x01, 0x01, 0x42, 0x9e, 0x01, 0x0a, 0x0e, 0x63, 0x6f, 0x6d, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, - 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x42, 0x0f, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, - 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x64, 0x65, 0x76, 0x2f, - 0x73, 0x64, 0x6b, 0x2d, 0x67, 0x6f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, - 0x63, 0x6f, 0x64, 0x65, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0xa2, 0x02, 0x03, - 0x48, 0x58, 0x58, 0xaa, 0x02, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, - 0xca, 0x02, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0xe2, 0x02, 0x16, - 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, - 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, - 0x72, 0x6c, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x75, 0x74, 0x4d, 0x69, 0x6c, 0x6c, 0x69, 0x73, 0x22, 0x0c, 0x0a, 0x0a, 0x52, 0x75, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x25, 0x0a, 0x0b, 0x52, 0x75, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x0f, + 0x0a, 0x0d, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, + 0x28, 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x0f, 0x0a, 0x0d, 0x46, 0x69, 0x6e, + 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x10, 0x0a, 0x0e, 0x46, 0x69, + 0x6e, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x4c, 0x0a, 0x07, + 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, + 0x6c, 0x6c, 0x6f, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, + 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, + 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x32, 0x98, 0x02, 0x0a, 0x07, 0x43, + 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x38, 0x0a, 0x03, 0x41, 0x64, 0x64, 0x12, 0x16, 0x2e, + 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x41, 0x64, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, + 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x3c, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, + 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x17, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x04, 0x98, 0x80, 0x01, 0x02, 0x12, 0x4d, + 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x57, 0x61, 0x74, 0x63, 0x68, 0x65, 0x72, 0x12, 0x1d, 0x2e, 0x68, + 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x41, 0x64, 0x64, 0x57, 0x61, 0x74, + 0x63, 0x68, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x68, 0x65, + 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x41, 0x64, 0x64, 0x57, 0x61, 0x74, 0x63, + 0x68, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, + 0x05, 0x57, 0x61, 0x74, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, + 0x72, 0x6c, 0x64, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x17, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x04, 0x98, 0x80, 0x01, 0x02, 0x1a, + 0x04, 0x98, 0x80, 0x01, 0x01, 0x32, 0xd0, 0x01, 0x0a, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x66, 0x6c, + 0x6f, 0x77, 0x12, 0x38, 0x0a, 0x03, 0x52, 0x75, 0x6e, 0x12, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, + 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x52, 0x75, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x17, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x52, + 0x75, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x41, 0x0a, 0x06, + 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x12, 0x19, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, + 0x72, 0x6c, 0x64, 0x2e, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1a, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x46, + 0x69, 0x6e, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x41, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x19, 0x2e, 0x68, 0x65, 0x6c, 0x6c, + 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, + 0x64, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x1a, 0x04, 0x98, 0x80, 0x01, 0x02, 0x42, 0x9e, 0x01, 0x0a, 0x0e, 0x63, 0x6f, 0x6d, + 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x42, 0x0f, 0x48, 0x65, 0x6c, + 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x64, 0x65, 0x76, 0x2f, 0x73, 0x64, 0x6b, 0x2d, 0x67, 0x6f, 0x2f, 0x65, 0x78, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x67, 0x65, 0x6e, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0xa2, 0x02, 0x03, 0x48, 0x58, 0x58, 0xaa, 0x02, 0x0a, 0x48, 0x65, 0x6c, 0x6c, + 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0xca, 0x02, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, + 0x72, 0x6c, 0x64, 0xe2, 0x02, 0x16, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, + 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0a, 0x48, + 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -452,7 +721,7 @@ func file_proto_helloworld_proto_rawDescGZIP() []byte { return file_proto_helloworld_proto_rawDescData } -var file_proto_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_proto_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_proto_helloworld_proto_goTypes = []any{ (*HelloRequest)(nil), // 0: helloworld.HelloRequest (*HelloResponse)(nil), // 1: helloworld.HelloResponse @@ -462,23 +731,35 @@ var file_proto_helloworld_proto_goTypes = []any{ (*AddWatcherRequest)(nil), // 5: helloworld.AddWatcherRequest (*AddWatcherResponse)(nil), // 6: helloworld.AddWatcherResponse (*WatchRequest)(nil), // 7: helloworld.WatchRequest + (*RunRequest)(nil), // 8: helloworld.RunRequest + (*RunResponse)(nil), // 9: helloworld.RunResponse + (*StatusRequest)(nil), // 10: helloworld.StatusRequest + (*StatusResponse)(nil), // 11: helloworld.StatusResponse + (*FinishRequest)(nil), // 12: helloworld.FinishRequest + (*FinishResponse)(nil), // 13: helloworld.FinishResponse } var file_proto_helloworld_proto_depIdxs = []int32{ - 0, // 0: helloworld.Greeter.SayHello:input_type -> helloworld.HelloRequest - 2, // 1: helloworld.Counter.Add:input_type -> helloworld.AddRequest - 3, // 2: helloworld.Counter.Get:input_type -> helloworld.GetRequest - 5, // 3: helloworld.Counter.AddWatcher:input_type -> helloworld.AddWatcherRequest - 7, // 4: helloworld.Counter.Watch:input_type -> helloworld.WatchRequest - 1, // 5: helloworld.Greeter.SayHello:output_type -> helloworld.HelloResponse - 4, // 6: helloworld.Counter.Add:output_type -> helloworld.GetResponse - 4, // 7: helloworld.Counter.Get:output_type -> helloworld.GetResponse - 6, // 8: helloworld.Counter.AddWatcher:output_type -> helloworld.AddWatcherResponse - 4, // 9: helloworld.Counter.Watch:output_type -> helloworld.GetResponse - 5, // [5:10] is the sub-list for method output_type - 0, // [0:5] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 0, // 0: helloworld.Greeter.SayHello:input_type -> helloworld.HelloRequest + 2, // 1: helloworld.Counter.Add:input_type -> helloworld.AddRequest + 3, // 2: helloworld.Counter.Get:input_type -> helloworld.GetRequest + 5, // 3: helloworld.Counter.AddWatcher:input_type -> helloworld.AddWatcherRequest + 7, // 4: helloworld.Counter.Watch:input_type -> helloworld.WatchRequest + 8, // 5: helloworld.Workflow.Run:input_type -> helloworld.RunRequest + 12, // 6: helloworld.Workflow.Finish:input_type -> helloworld.FinishRequest + 10, // 7: helloworld.Workflow.Status:input_type -> helloworld.StatusRequest + 1, // 8: helloworld.Greeter.SayHello:output_type -> helloworld.HelloResponse + 4, // 9: helloworld.Counter.Add:output_type -> helloworld.GetResponse + 4, // 10: helloworld.Counter.Get:output_type -> helloworld.GetResponse + 6, // 11: helloworld.Counter.AddWatcher:output_type -> helloworld.AddWatcherResponse + 4, // 12: helloworld.Counter.Watch:output_type -> helloworld.GetResponse + 9, // 13: helloworld.Workflow.Run:output_type -> helloworld.RunResponse + 13, // 14: helloworld.Workflow.Finish:output_type -> helloworld.FinishResponse + 11, // 15: helloworld.Workflow.Status:output_type -> helloworld.StatusResponse + 8, // [8:16] is the sub-list for method output_type + 0, // [0:8] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_proto_helloworld_proto_init() } @@ -583,6 +864,78 @@ func file_proto_helloworld_proto_init() { return nil } } + file_proto_helloworld_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*RunRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_helloworld_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*RunResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_helloworld_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*StatusRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_helloworld_proto_msgTypes[11].Exporter = func(v any, i int) any { + switch v := v.(*StatusResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_helloworld_proto_msgTypes[12].Exporter = func(v any, i int) any { + switch v := v.(*FinishRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_helloworld_proto_msgTypes[13].Exporter = func(v any, i int) any { + switch v := v.(*FinishResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -590,9 +943,9 @@ func file_proto_helloworld_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_helloworld_proto_rawDesc, NumEnums: 0, - NumMessages: 8, + NumMessages: 14, NumExtensions: 0, - NumServices: 2, + NumServices: 3, }, GoTypes: file_proto_helloworld_proto_goTypes, DependencyIndexes: file_proto_helloworld_proto_depIdxs, diff --git a/examples/codegen/proto/helloworld.proto b/examples/codegen/proto/helloworld.proto index 127d1e0..693f0fe 100644 --- a/examples/codegen/proto/helloworld.proto +++ b/examples/codegen/proto/helloworld.proto @@ -26,6 +26,16 @@ service Counter { } } +service Workflow { + option (dev.restate.sdk.go.service_type) = WORKFLOW; + // Execute the workflow + rpc Run (RunRequest) returns (RunResponse) {} + // Unblock the workflow + rpc Finish(FinishRequest) returns (FinishResponse) {} + // Check the current status + rpc Status (StatusRequest) returns (StatusResponse) {} +} + message HelloRequest { string name = 1; } @@ -53,3 +63,19 @@ message AddWatcherResponse {} message WatchRequest { int64 timeout_millis = 1; } + +message RunRequest {} + +message RunResponse { + string status = 1; +} + +message StatusRequest {} + +message StatusResponse { + string status = 1; +} + +message FinishRequest {} + +message FinishResponse {} diff --git a/examples/codegen/proto/helloworld_restate.pb.go b/examples/codegen/proto/helloworld_restate.pb.go index 01f3c21..19d78f0 100644 --- a/examples/codegen/proto/helloworld_restate.pb.go +++ b/examples/codegen/proto/helloworld_restate.pb.go @@ -192,3 +192,104 @@ func NewCounterServer(srv CounterServer, opts ...sdk_go.ServiceDefinitionOption) router = router.Handler("Watch", sdk_go.NewObjectSharedHandler(srv.Watch)) return router } + +// WorkflowClient is the client API for Workflow service. +type WorkflowClient interface { + // Execute the workflow + Run(opts ...sdk_go.ClientOption) sdk_go.Client[*RunRequest, *RunResponse] + // Unblock the workflow + Finish(opts ...sdk_go.ClientOption) sdk_go.Client[*FinishRequest, *FinishResponse] + // Check the current status + Status(opts ...sdk_go.ClientOption) sdk_go.Client[*StatusRequest, *StatusResponse] +} + +type workflowClient struct { + ctx sdk_go.Context + workflowID string + options []sdk_go.ClientOption +} + +func NewWorkflowClient(ctx sdk_go.Context, workflowID string, opts ...sdk_go.ClientOption) WorkflowClient { + cOpts := append([]sdk_go.ClientOption{sdk_go.WithProtoJSON}, opts...) + return &workflowClient{ + ctx, + workflowID, + cOpts, + } +} +func (c *workflowClient) Run(opts ...sdk_go.ClientOption) sdk_go.Client[*RunRequest, *RunResponse] { + cOpts := c.options + if len(opts) > 0 { + cOpts = append(append([]sdk_go.ClientOption{}, cOpts...), opts...) + } + return sdk_go.WithRequestType[*RunRequest](sdk_go.Workflow[*RunResponse](c.ctx, "Workflow", c.workflowID, "Run", cOpts...)) +} + +func (c *workflowClient) Finish(opts ...sdk_go.ClientOption) sdk_go.Client[*FinishRequest, *FinishResponse] { + cOpts := c.options + if len(opts) > 0 { + cOpts = append(append([]sdk_go.ClientOption{}, cOpts...), opts...) + } + return sdk_go.WithRequestType[*FinishRequest](sdk_go.Workflow[*FinishResponse](c.ctx, "Workflow", c.workflowID, "Finish", cOpts...)) +} + +func (c *workflowClient) Status(opts ...sdk_go.ClientOption) sdk_go.Client[*StatusRequest, *StatusResponse] { + cOpts := c.options + if len(opts) > 0 { + cOpts = append(append([]sdk_go.ClientOption{}, cOpts...), opts...) + } + return sdk_go.WithRequestType[*StatusRequest](sdk_go.Workflow[*StatusResponse](c.ctx, "Workflow", c.workflowID, "Status", cOpts...)) +} + +// WorkflowServer is the server API for Workflow service. +// All implementations should embed UnimplementedWorkflowServer +// for forward compatibility. +type WorkflowServer interface { + // Execute the workflow + Run(ctx sdk_go.WorkflowContext, req *RunRequest) (*RunResponse, error) + // Unblock the workflow + Finish(ctx sdk_go.WorkflowSharedContext, req *FinishRequest) (*FinishResponse, error) + // Check the current status + Status(ctx sdk_go.WorkflowSharedContext, req *StatusRequest) (*StatusResponse, error) +} + +// UnimplementedWorkflowServer should be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedWorkflowServer struct{} + +func (UnimplementedWorkflowServer) Run(ctx sdk_go.WorkflowContext, req *RunRequest) (*RunResponse, error) { + return nil, sdk_go.TerminalError(fmt.Errorf("method Run not implemented"), 501) +} +func (UnimplementedWorkflowServer) Finish(ctx sdk_go.WorkflowSharedContext, req *FinishRequest) (*FinishResponse, error) { + return nil, sdk_go.TerminalError(fmt.Errorf("method Finish not implemented"), 501) +} +func (UnimplementedWorkflowServer) Status(ctx sdk_go.WorkflowSharedContext, req *StatusRequest) (*StatusResponse, error) { + return nil, sdk_go.TerminalError(fmt.Errorf("method Status not implemented"), 501) +} +func (UnimplementedWorkflowServer) testEmbeddedByValue() {} + +// UnsafeWorkflowServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to WorkflowServer will +// result in compilation errors. +type UnsafeWorkflowServer interface { + mustEmbedUnimplementedWorkflowServer() +} + +func NewWorkflowServer(srv WorkflowServer, opts ...sdk_go.ServiceDefinitionOption) sdk_go.ServiceDefinition { + // If the following call panics, it indicates UnimplementedWorkflowServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + sOpts := append([]sdk_go.ServiceDefinitionOption{sdk_go.WithProtoJSON}, opts...) + router := sdk_go.NewWorkflow("Workflow", sOpts...) + router = router.Handler("Run", sdk_go.NewWorkflowHandler(srv.Run)) + router = router.Handler("Finish", sdk_go.NewWorkflowSharedHandler(srv.Finish)) + router = router.Handler("Status", sdk_go.NewWorkflowSharedHandler(srv.Status)) + return router +}