Skip to content

Commit dc356e8

Browse files
authored
Merge create callback and create subscrition (#681)
* Merge create callback and create subscrition These will be separate api subsystem requests but the same coroutine.
1 parent 9f700b4 commit dc356e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2784
-2600
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ resonate.yml
3333
coverage.out
3434
dst*.html
3535
redoc-static.html
36+
api/index.html

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ gen-proto:
33
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/promise_t.proto
44
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/promise.proto
55
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/callback_t.proto
6-
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/callback.proto
7-
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/subscription.proto
86
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/schedule_t.proto
97
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/schedule.proto
108
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/app/subsystems/api/grpc/pb/lock.proto

api/openapi.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,19 @@ paths:
316316
404:
317317
description: Promise not found
318318

319-
# Callbacks
320-
/callbacks:
319+
/promises/callback/{id}:
321320
post:
322321
tags:
323-
- Callbacks
324-
summary: Create callback
325-
operationId: createCallback
322+
- Promises
323+
summary: Create promise callback
324+
operationId: createPromiseCallback
326325
parameters:
326+
- in: path
327+
name: id
328+
required: true
329+
description: The promise id
330+
schema:
331+
type: string
327332
- in: header
328333
name: request-id
329334
description: Unique tracking id
@@ -336,16 +341,10 @@ paths:
336341
schema:
337342
type: object
338343
required:
339-
- id
340-
- promiseId
341344
- rootPromiseId
342345
- timeout
343346
- recv
344347
properties:
345-
id:
346-
type: string
347-
promiseId:
348-
type: string
349348
rootPromiseId:
350349
type: string
351350
timeout:
@@ -377,14 +376,19 @@ paths:
377376
404:
378377
description: Promise not found
379378

380-
# Subscriptions
381-
/subscriptions:
379+
/promises/subscribe/{id}:
382380
post:
383381
tags:
384-
- Subscription
385-
summary: Create a Subscription
386-
operationId: createSubscription
382+
- Promises
383+
summary: Create promise subscription
384+
operationId: createPromiseSubscription
387385
parameters:
386+
- in: path
387+
name: id
388+
required: true
389+
description: The promise id
390+
schema:
391+
type: string
388392
- in: header
389393
name: request-id
390394
description: Unique tracking id
@@ -398,14 +402,11 @@ paths:
398402
type: object
399403
required:
400404
- id
401-
- promiseId
402405
- timeout
403406
- recv
404407
properties:
405408
id:
406409
type: string
407-
promiseId:
408-
type: string
409410
timeout:
410411
type: integer
411412
format: int64

cmd/callbacks/callbacks.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

cmd/dst/run.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/resonatehq/resonate/internal/aio"
1616
"github.com/resonatehq/resonate/internal/api"
1717
"github.com/resonatehq/resonate/internal/app/coroutines"
18+
"github.com/resonatehq/resonate/internal/app/validators"
1819
"github.com/resonatehq/resonate/internal/kernel/system"
1920
"github.com/resonatehq/resonate/internal/kernel/t_api"
2021
"github.com/resonatehq/resonate/internal/metrics"
@@ -127,6 +128,9 @@ func RunDSTCmd() *cobra.Command {
127128
aio.AddSubsystem(subsystem)
128129
}
129130

131+
// api validators
132+
api.AddValidator(t_api.CreateCallback, validators.CreateCallback)
133+
130134
// start api/aio
131135
if err := api.Start(); err != nil {
132136
return err
@@ -145,7 +149,6 @@ func RunDSTCmd() *cobra.Command {
145149
system.AddOnRequest(t_api.CreatePromiseAndTask, coroutines.CreatePromiseAndTask)
146150
system.AddOnRequest(t_api.CompletePromise, coroutines.CompletePromise)
147151
system.AddOnRequest(t_api.CreateCallback, coroutines.CreateCallback)
148-
system.AddOnRequest(t_api.CreateSubscription, coroutines.CreateSubscription)
149152
system.AddOnRequest(t_api.ReadSchedule, coroutines.ReadSchedule)
150153
system.AddOnRequest(t_api.SearchSchedules, coroutines.SearchSchedules)
151154
system.AddOnRequest(t_api.CreateSchedule, coroutines.CreateSchedule)

cmd/projects/scaffold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func setup(url, dest string) error {
3838
if err := download(url, tmp); err != nil {
3939
return err
4040
}
41-
defer util.DeferAndLog(func() error {return os.Remove(tmp)})
41+
defer util.DeferAndLog(func() error { return os.Remove(tmp) })
4242

4343
if err := unzip(tmp, dest); err != nil {
4444
return err

cmd/callbacks/create.go renamed to cmd/promises/callback.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package callbacks
1+
package promises
22

33
import (
44
"context"
@@ -7,39 +7,39 @@ import (
77
"strings"
88
"time"
99

10+
"github.com/resonatehq/resonate/internal/util"
1011
"github.com/resonatehq/resonate/pkg/client"
1112
v1 "github.com/resonatehq/resonate/pkg/client/v1"
1213
"github.com/spf13/cobra"
1314
)
1415

15-
var createCallbacksExample = `
16+
var createPromiseCallbackExample = `
1617
# Create a callback
17-
resonate callback create foo --promise-id bar --root-promise-id baz --timeout 1h --recv default
18+
resonate promises callback foo --root-promise-id bar --timeout 1h --recv default
1819
1920
# Create a callback with url
20-
resonate callback create foo --promise-id bar --root-promise-id baz --timeout 1h --recv poll://default/6fa89b7e-4a56-40e8-ba4e-78864caa3278
21+
resonate promises callback foo --root-promise-id bar --timeout 1h --recv poll://default/1
2122
2223
# Create a callback with object
23-
resonate callback create foo --promise-id bar --root-promise-id baz --timeout 1h --recv {"type": "poll", "data": {"group": "default", "id": "6fa89b7e-4a56-40e8-ba4e-78864caa3278"}}
24+
resonate promises callback foo --root-promise-id bar --timeout 1h --recv {"type": "poll", "data": {"group": "default", "id": "2"}}
2425
`
2526

26-
func CreateCallbackCmd(c client.Client) *cobra.Command {
27+
func CreatePromiseCallbackCmd(c client.Client) *cobra.Command {
2728
var (
28-
promiseId string
2929
rootPromiseId string
30-
timeout time.Duration
3130
recvStr string
31+
timeout time.Duration
3232
)
3333
cmd := &cobra.Command{
34-
Use: "create <id>",
34+
Use: "callback <id>",
3535
Short: "Create callback",
36-
Example: createCallbacksExample,
36+
Example: createPromiseCallbackExample,
3737
RunE: func(cmd *cobra.Command, args []string) error {
3838
if len(args) != 1 {
39-
return errors.New("must specify an id")
39+
return errors.New("must specify a promise id")
4040
}
4141

42-
id := args[0]
42+
promiseId := args[0]
4343

4444
var recv v1.Recv
4545

@@ -58,26 +58,24 @@ func CreateCallbackCmd(c client.Client) *cobra.Command {
5858
}
5959
}
6060

61-
body := v1.CreateCallbackJSONRequestBody{
62-
Id: id,
63-
PromiseId: promiseId,
61+
body := v1.CreatePromiseCallbackJSONRequestBody{
6462
RootPromiseId: rootPromiseId,
65-
Timeout: time.Now().Add(timeout).UnixMilli(),
6663
Recv: recv,
64+
Timeout: time.Now().Add(timeout).UnixMilli(),
6765
}
6866

69-
res, err := c.V1().CreateCallbackWithResponse(context.TODO(), nil, body)
67+
res, err := c.V1().CreatePromiseCallbackWithResponse(context.TODO(), promiseId, nil, body)
7068
if err != nil {
7169
return err
7270
}
7371

7472
if res.StatusCode() == 201 {
75-
cmd.Printf("Created callback: %s\n", id)
73+
cmd.Printf("Created callback: %s\n", util.ResumeId(rootPromiseId, promiseId))
7674
} else if res.StatusCode() == 200 {
7775
if res.JSON200.Promise != nil && res.JSON200.Promise.State != v1.PromiseStatePENDING {
7876
cmd.Printf("Promise %s already %s\n", promiseId, strings.ToLower(string(res.JSON200.Promise.State)))
7977
} else {
80-
cmd.Printf("Created callback: %s (deduplicated)\n", id)
78+
cmd.Printf("Created callback: %s (deduplicated)\n", util.ResumeId(rootPromiseId, promiseId))
8179
}
8280
} else {
8381
cmd.PrintErrln(res.Status(), string(res.Body))
@@ -87,12 +85,10 @@ func CreateCallbackCmd(c client.Client) *cobra.Command {
8785
},
8886
}
8987

90-
cmd.Flags().StringVar(&promiseId, "promise-id", "", "promise id")
9188
cmd.Flags().StringVar(&rootPromiseId, "root-promise-id", "", "root promise id")
92-
cmd.Flags().DurationVar(&timeout, "timeout", 0, "task timeout")
9389
cmd.Flags().StringVar(&recvStr, "recv", "default", "task receiver")
90+
cmd.Flags().DurationVar(&timeout, "timeout", 0, "task timeout")
9491

95-
_ = cmd.MarkFlagRequired("promise-id")
9692
_ = cmd.MarkFlagRequired("root-promise-id")
9793
_ = cmd.MarkFlagRequired("timeout")
9894

cmd/promises/promises.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func NewCmd() *cobra.Command {
4040
cmd.AddCommand(SearchPromisesCmd(c))
4141
cmd.AddCommand(CreatePromiseCmd(c))
4242
cmd.AddCommand(CompletePromiseCmds(c)...)
43+
cmd.AddCommand(CreatePromiseCallbackCmd(c))
44+
cmd.AddCommand(CreateSubscriptionCmd(c))
4345

4446
// Flags
4547
cmd.PersistentFlags().StringVarP(&server, "server", "", "http://localhost:8001", "resonate url")

cmd/promises/search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13-
var searchPromiseExample = `
13+
var searchPromisesExample = `
1414
# Search for all promises
1515
resonate promises search "*"
1616
@@ -38,7 +38,7 @@ func SearchPromisesCmd(c client.Client) *cobra.Command {
3838
cmd := &cobra.Command{
3939
Use: "search <q>",
4040
Short: "Search promises",
41-
Example: searchPromiseExample,
41+
Example: searchPromisesExample,
4242
RunE: func(cmd *cobra.Command, args []string) error {
4343
if len(args) != 1 {
4444
return errors.New("must specify search query")

0 commit comments

Comments
 (0)