Skip to content

Commit

Permalink
Change grpc state to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
dfarr committed Aug 25, 2023
1 parent d071c4d commit 3fd3ad0
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 95 deletions.
230 changes: 147 additions & 83 deletions internal/app/subsystems/api/grpc/api/promise.pb.go

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

10 changes: 9 additions & 1 deletion internal/app/subsystems/api/grpc/api/promise.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ option go_package = "github.com/resonatehq/resonate/internal/app/subsystems/api/

message Promise {
string id = 1;
string state = 2;
State state = 2;
Value param = 3;
Value value = 4;
int64 timeout = 5;
}

enum State {
PENDING = 0;
RESOLVED = 1;
REJECTED = 2;
REJECTED_TIMEDOUT = 3;
REJECTED_CANCELED = 4;
}

message Subscription {
int64 id = 1;
string url = 2;
Expand Down
20 changes: 18 additions & 2 deletions internal/app/subsystems/api/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net"
"strings"

"github.com/resonatehq/resonate/internal/api"
grpcApi "github.com/resonatehq/resonate/internal/app/subsystems/api/grpc/api"
Expand Down Expand Up @@ -473,7 +472,7 @@ func protoPromise(promise *promise.Promise) *grpcApi.Promise {

return &grpcApi.Promise{
Id: promise.Id,
State: strings.ToUpper(promise.State.String()),
State: protoState(promise.State),
Param: &grpcApi.Value{
Headers: promise.Param.Headers,
Ikey: paramIkey,
Expand All @@ -488,6 +487,23 @@ func protoPromise(promise *promise.Promise) *grpcApi.Promise {
}
}

func protoState(state promise.State) grpcApi.State {
switch state {
case promise.Pending:
return grpcApi.State_PENDING
case promise.Resolved:
return grpcApi.State_RESOLVED
case promise.Rejected:
return grpcApi.State_REJECTED
case promise.Timedout:
return grpcApi.State_REJECTED_TIMEDOUT
case promise.Canceled:
return grpcApi.State_REJECTED_CANCELED
default:
panic("invalid state")
}
}

func protoSubscription(subscription *subscription.Subscription) *grpcApi.Subscription {
if subscription == nil {
return nil
Expand Down
Loading

0 comments on commit 3fd3ad0

Please sign in to comment.