Skip to content

Commit

Permalink
Consolidated t_api Kind.
Browse files Browse the repository at this point in the history
  • Loading branch information
favalos committed Jan 30, 2024
1 parent 538937b commit aefc288
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 233 deletions.
8 changes: 2 additions & 6 deletions cmd/dst/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ func RunDSTCmd() *cobra.Command {
system.AddOnRequest(t_api.ReadPromise, coroutines.ReadPromise)
system.AddOnRequest(t_api.SearchPromises, coroutines.SearchPromises)
system.AddOnRequest(t_api.CreatePromise, coroutines.CreatePromise)
system.AddOnRequest(t_api.CancelPromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.RejectPromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.ResolvePromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.CompletePromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.ReadSchedule, coroutines.ReadSchedule)
system.AddOnRequest(t_api.SearchSchedules, coroutines.SearchSchedules)
system.AddOnRequest(t_api.CreateSchedule, coroutines.CreateSchedule)
Expand All @@ -133,9 +131,7 @@ func RunDSTCmd() *cobra.Command {
t_api.ReadPromise,
t_api.SearchPromises,
t_api.CreatePromise,
t_api.CancelPromise,
t_api.RejectPromise,
t_api.ResolvePromise,
t_api.CompletePromise,

// SCHEDULE
t_api.ReadSchedule,
Expand Down
4 changes: 1 addition & 3 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ func ServeCmd() *cobra.Command {
system.AddOnRequest(t_api.ReadPromise, coroutines.ReadPromise)
system.AddOnRequest(t_api.SearchPromises, coroutines.SearchPromises)
system.AddOnRequest(t_api.CreatePromise, coroutines.CreatePromise)
system.AddOnRequest(t_api.CancelPromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.RejectPromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.ResolvePromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.CompletePromise, coroutines.CompletePromise)
system.AddOnRequest(t_api.ReadSchedule, coroutines.ReadSchedule)
system.AddOnRequest(t_api.SearchSchedules, coroutines.SearchSchedules)
system.AddOnRequest(t_api.CreateSchedule, coroutines.CreateSchedule)
Expand Down
6 changes: 1 addition & 5 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ func (a *api) Enqueue(sqe *bus.SQE[t_api.Request, t_api.Response]) {
status = int(res.SearchPromises.Status)
case t_api.CreatePromise:
status = int(res.CreatePromise.Status)
case t_api.CancelPromise:
status = int(res.CompletePromise.Status)
case t_api.RejectPromise:
status = int(res.CompletePromise.Status)
case t_api.ResolvePromise:
case t_api.CompletePromise:
status = int(res.CompletePromise.Status)
case t_api.ReadSchedule:
status = int(res.ReadSchedule.Status)
Expand Down
36 changes: 18 additions & 18 deletions internal/app/subsystems/api/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func TestCancelPromise(t *testing.T) {
},
},
req: &t_api.Request{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: util.ToPointer(idempotency.Key("bar")),
Expand All @@ -557,7 +557,7 @@ func TestCancelPromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -574,7 +574,7 @@ func TestCancelPromise(t *testing.T) {
Id: "foo",
},
req: &t_api.Request{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -587,7 +587,7 @@ func TestCancelPromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -604,7 +604,7 @@ func TestCancelPromise(t *testing.T) {
Id: "foo",
},
req: &t_api.Request{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -617,7 +617,7 @@ func TestCancelPromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusPromiseAlreadyResolved,
Promise: &promise.Promise{
Expand Down Expand Up @@ -687,7 +687,7 @@ func TestResolvePromise(t *testing.T) {
},
},
req: &t_api.Request{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: util.ToPointer(idempotency.Key("bar")),
Expand All @@ -700,7 +700,7 @@ func TestResolvePromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -717,7 +717,7 @@ func TestResolvePromise(t *testing.T) {
Id: "foo",
},
req: &t_api.Request{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -730,7 +730,7 @@ func TestResolvePromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -747,7 +747,7 @@ func TestResolvePromise(t *testing.T) {
Id: "foo",
},
req: &t_api.Request{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -760,7 +760,7 @@ func TestResolvePromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusPromiseAlreadyRejected,
Promise: &promise.Promise{
Expand Down Expand Up @@ -830,7 +830,7 @@ func TestRejectPromise(t *testing.T) {
},
},
req: &t_api.Request{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: util.ToPointer(idempotency.Key("bar")),
Expand All @@ -843,7 +843,7 @@ func TestRejectPromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -860,7 +860,7 @@ func TestRejectPromise(t *testing.T) {
Id: "foo",
},
req: &t_api.Request{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -873,7 +873,7 @@ func TestRejectPromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -890,7 +890,7 @@ func TestRejectPromise(t *testing.T) {
Id: "foo",
},
req: &t_api.Request{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -903,7 +903,7 @@ func TestRejectPromise(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusPromiseAlreadyResolved,
Promise: &promise.Promise{
Expand Down
24 changes: 12 additions & 12 deletions internal/app/subsystems/api/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func TestHttpServer(t *testing.T) {
}
}`),
req: &t_api.Request{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo/bar",
IdempotencyKey: util.ToPointer(idempotency.Key("bar")),
Expand All @@ -426,7 +426,7 @@ func TestHttpServer(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -445,7 +445,7 @@ func TestHttpServer(t *testing.T) {
"state": "REJECTED_CANCELED"
}`),
req: &t_api.Request{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -458,7 +458,7 @@ func TestHttpServer(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.CancelPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -485,7 +485,7 @@ func TestHttpServer(t *testing.T) {
}
}`),
req: &t_api.Request{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo/bar",
IdempotencyKey: util.ToPointer(idempotency.Key("bar")),
Expand All @@ -498,7 +498,7 @@ func TestHttpServer(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -517,7 +517,7 @@ func TestHttpServer(t *testing.T) {
"state": "RESOLVED"
}`),
req: &t_api.Request{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -530,7 +530,7 @@ func TestHttpServer(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.ResolvePromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -557,7 +557,7 @@ func TestHttpServer(t *testing.T) {
}
}`),
req: &t_api.Request{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo/bar",
IdempotencyKey: util.ToPointer(idempotency.Key("bar")),
Expand All @@ -570,7 +570,7 @@ func TestHttpServer(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand All @@ -589,7 +589,7 @@ func TestHttpServer(t *testing.T) {
"state": "REJECTED"
}`),
req: &t_api.Request{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: "foo",
IdempotencyKey: nil,
Expand All @@ -602,7 +602,7 @@ func TestHttpServer(t *testing.T) {
},
},
res: &t_api.Response{
Kind: t_api.RejectPromise,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseResponse{
Status: t_api.StatusCreated,
Promise: &promise.Promise{
Expand Down
18 changes: 1 addition & 17 deletions internal/app/subsystems/api/service/promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,10 @@ func (s *Service) CreatePromise(header *CreatePromiseHeader, body *promise.Promi
func (s *Service) CompletePromise(id string, state promise.State, header *CompletePromiseHeader, body *CompletePromiseBody) (*t_api.CompletePromiseResponse, error) {
cq := make(chan *bus.CQE[t_api.Request, t_api.Response], 1)

var kind = ToKind(state)

s.api.Enqueue(&bus.SQE[t_api.Request, t_api.Response]{
Metadata: s.metadata(header.RequestId, "complete-promise"),
Submission: &t_api.Request{
Kind: kind,
Kind: t_api.CompletePromise,
CompletePromise: &t_api.CompletePromiseRequest{
Id: id,
IdempotencyKey: header.IdempotencyKey,
Expand Down Expand Up @@ -209,17 +207,3 @@ func (s *Service) CompletePromise(id string, state promise.State, header *Comple
// success
return cqe.Completion.CompletePromise, nil
}

func ToKind(state promise.State) t_api.Kind {

switch state {
case promise.Canceled:
return t_api.CancelPromise
case promise.Rejected:
return t_api.RejectPromise
case promise.Resolved:
return t_api.ResolvePromise
default:
panic("State not valid.")
}
}
27 changes: 3 additions & 24 deletions internal/kernel/t_api/api.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package t_api

import "github.com/resonatehq/resonate/pkg/promise"

type Kind int

const (
// PROMISES
ReadPromise Kind = iota
SearchPromises
CreatePromise
CancelPromise
ResolvePromise
RejectPromise
CompletePromise

// SCHEDULES
ReadSchedule
Expand Down Expand Up @@ -42,12 +38,8 @@ func (k Kind) String() string {
return "search-promises"
case CreatePromise:
return "create-promise"
case CancelPromise:
return "cancel-promise"
case ResolvePromise:
return "resolve-promise"
case RejectPromise:
return "reject-promise"
case CompletePromise:
return "complete-promise"
// SCHEDULES
case ReadSchedule:
return "read-schedule"
Expand Down Expand Up @@ -75,16 +67,3 @@ func (k Kind) String() string {
panic("invalid api")
}
}

func From(state promise.State) Kind {
switch state {
case promise.Canceled:
return CancelPromise
case promise.Rejected:
return RejectPromise
case promise.Resolved:
return ResolvePromise
default:
panic("invalid state")
}
}
Loading

0 comments on commit aefc288

Please sign in to comment.