Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout promises before search request #70

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ services:
command:
- dst
- run
- --aio-store
- postgres
- --aio-store-postgres-host
- postgres-dst
- --aio-store-postgres-username
Expand Down
75 changes: 26 additions & 49 deletions internal/app/coroutines/cancelPromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
Id: req.CancelPromise.Id,
},
},
{
Kind: types.StoreReadSubscriptions,
ReadSubscriptions: &types.ReadSubscriptionsCommand{
PromiseIds: []string{req.CancelPromise.Id},
},
},
},
},
},
Expand All @@ -49,11 +43,8 @@
}

util.Assert(completion.Store != nil, "completion must not be nil")
util.Assert(len(completion.Store.Results) == 2, "completion must contain two results")

result := completion.Store.Results[0].ReadPromise
records := completion.Store.Results[1].ReadSubscriptions.Records

util.Assert(result.RowsReturned == 0 || result.RowsReturned == 1, "result must return 0 or 1 rows")

if result.RowsReturned == 0 {
Expand All @@ -73,7 +64,7 @@

if p.State == promise.Pending {
if t >= p.Timeout {
s.Add(TimeoutPromise(t, p, records, CancelPromise(t, req, res), func(t int64, err error) {
s.Add(TimeoutPromise(t, p, CancelPromise(t, req, res), func(t int64, err error) {
if err != nil {
slog.Error("failed to timeout promise", "req", req, "err", err)
res(t, nil, err)
Expand Down Expand Up @@ -102,55 +93,41 @@
}, nil)
}))
} else {
commands := []*types.Command{
{
Kind: types.StoreUpdatePromise,
UpdatePromise: &types.UpdatePromiseCommand{
Id: req.CancelPromise.Id,
State: promise.Canceled,
Value: req.CancelPromise.Value,
CompletedOn: t,
},
},
{
Kind: types.StoreDeleteTimeout,
DeleteTimeout: &types.DeleteTimeoutCommand{
Id: req.CancelPromise.Id,
},
},
{
Kind: types.StoreDeleteSubscriptions,
DeleteSubscriptions: &types.DeleteSubscriptionsCommand{
PromiseId: req.CancelPromise.Id,
},
},
}

for _, record := range records {
commands = append(commands, &types.Command{
Kind: types.StoreCreateNotification,
CreateNotification: &types.CreateNotificationCommand{
Id: record.Id,
PromiseId: record.PromiseId,
Url: record.Url,
RetryPolicy: record.RetryPolicy,
Time: t,
},
})
}

submission := &types.Submission{
Kind: types.Store,
Store: &types.StoreSubmission{
Transaction: &types.Transaction{
Commands: commands,
Commands: []*types.Command{
{
Kind: types.StoreUpdatePromise,
UpdatePromise: &types.UpdatePromiseCommand{
Id: req.CancelPromise.Id,
State: promise.Canceled,
Value: req.CancelPromise.Value,
CompletedOn: t,
},
},
{
Kind: types.StoreCreateNotifications,
CreateNotifications: &types.CreateNotificationsCommand{
PromiseId: req.CancelPromise.Id,
Time: t,
},
},
{
Kind: types.StoreDeleteSubscriptions,
DeleteSubscriptions: &types.DeleteSubscriptionsCommand{
PromiseId: req.CancelPromise.Id,
},
},
},
},
},
}

c.Yield(submission, func(t int64, completion *types.Completion, err error) {
if err != nil {
slog.Error("failed to update state", "req", req, "err", err)
slog.Error("failed to update promise", "req", req, "err", err)

Check warning on line 130 in internal/app/coroutines/cancelPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/cancelPromise.go#L130

Added line #L130 was not covered by tests
res(t, nil, err)
return
}
Expand Down
75 changes: 26 additions & 49 deletions internal/app/coroutines/completePromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
Id: req.CompletePromise.Id,
},
},
{
Kind: types.StoreReadSubscriptions,
ReadSubscriptions: &types.ReadSubscriptionsCommand{
PromiseIds: []string{req.CompletePromise.Id},
},
},
},
},
},
Expand All @@ -51,11 +45,8 @@
}

util.Assert(completion.Store != nil, "completion must not be nil")
util.Assert(len(completion.Store.Results) == 2, "completion must contain two results")

result := completion.Store.Results[0].ReadPromise
records := completion.Store.Results[1].ReadSubscriptions.Records

util.Assert(result.RowsReturned == 0 || result.RowsReturned == 1, "result must return 0 or 1 rows")

if result.RowsReturned == 0 {
Expand All @@ -75,7 +66,7 @@

if p.State == promise.Pending {
if t >= p.Timeout {
s.Add(TimeoutPromise(t, p, records, CompletePromise(t, req, res), func(t int64, err error) {
s.Add(TimeoutPromise(t, p, CompletePromise(t, req, res), func(t int64, err error) {
if err != nil {
slog.Error("failed to timeout promise", "req", req, "err", err)
res(t, nil, err)
Expand Down Expand Up @@ -104,55 +95,41 @@
}, nil)
}))
} else {
commands := []*types.Command{
{
Kind: types.StoreUpdatePromise,
UpdatePromise: &types.UpdatePromiseCommand{
Id: req.CompletePromise.Id,
State: req.CompletePromise.State,
Value: req.CompletePromise.Value,
CompletedOn: t,
},
},
{
Kind: types.StoreDeleteTimeout,
DeleteTimeout: &types.DeleteTimeoutCommand{
Id: req.CompletePromise.Id,
},
},
{
Kind: types.StoreDeleteSubscriptions,
DeleteSubscriptions: &types.DeleteSubscriptionsCommand{
PromiseId: req.CompletePromise.Id,
},
},
}

for _, record := range records {
commands = append(commands, &types.Command{
Kind: types.StoreCreateNotification,
CreateNotification: &types.CreateNotificationCommand{
Id: record.Id,
PromiseId: record.PromiseId,
Url: record.Url,
RetryPolicy: record.RetryPolicy,
Time: t,
},
})
}

submission := &types.Submission{
Kind: types.Store,
Store: &types.StoreSubmission{
Transaction: &types.Transaction{
Commands: commands,
Commands: []*types.Command{
{
Kind: types.StoreUpdatePromise,
UpdatePromise: &types.UpdatePromiseCommand{
Id: req.CompletePromise.Id,
State: req.CompletePromise.State,
Value: req.CompletePromise.Value,
CompletedOn: t,
},
},
{
Kind: types.StoreCreateNotifications,
CreateNotifications: &types.CreateNotificationsCommand{
PromiseId: req.CompletePromise.Id,
Time: t,
},
},
{
Kind: types.StoreDeleteSubscriptions,
DeleteSubscriptions: &types.DeleteSubscriptionsCommand{
PromiseId: req.CompletePromise.Id,
},
},
},
},
},
}

c.Yield(submission, func(t int64, completion *types.Completion, err error) {
if err != nil {
slog.Error("failed to update state", "req", req, "err", err)
slog.Error("failed to update promise", "req", req, "err", err)

Check warning on line 132 in internal/app/coroutines/completePromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/completePromise.go#L132

Added line #L132 was not covered by tests
res(t, nil, err)
return
}
Expand Down
11 changes: 2 additions & 9 deletions internal/app/coroutines/createPromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,14 @@
CreatedOn: t,
},
},
{
Kind: types.StoreCreateTimeout,
CreateTimeout: &types.CreateTimeoutCommand{
Id: req.CreatePromise.Id,
Time: req.CreatePromise.Timeout,
},
},
},
},
},
}

c.Yield(submission, func(t int64, completion *types.Completion, err error) {
if err != nil {
slog.Error("failed to update state", "req", req, "err", err)
slog.Error("failed to update promise", "req", req, "err", err)

Check warning on line 76 in internal/app/coroutines/createPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/createPromise.go#L76

Added line #L76 was not covered by tests
res(t, nil, err)
return
}
Expand Down Expand Up @@ -125,7 +118,7 @@
}

if p.State == promise.Pending && t >= p.Timeout {
s.Add(TimeoutPromise(t, p, nil, CreatePromise(t, req, res), func(t int64, err error) {
s.Add(TimeoutPromise(t, p, CreatePromise(t, req, res), func(t int64, err error) {

Check warning on line 121 in internal/app/coroutines/createPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/createPromise.go#L121

Added line #L121 was not covered by tests
if err != nil {
slog.Error("failed to timeout promise", "req", req, "err", err)
res(t, nil, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/coroutines/readPromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}

if p.State == promise.Pending && t >= p.Timeout {
s.Add(TimeoutPromise(t, p, nil, ReadPromise(t, req, res), func(t int64, err error) {
s.Add(TimeoutPromise(t, p, ReadPromise(t, req, res), func(t int64, err error) {

Check warning on line 59 in internal/app/coroutines/readPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/readPromise.go#L59

Added line #L59 was not covered by tests
if err != nil {
slog.Error("failed to timeout promise", "req", req, "err", err)
res(t, nil, err)
Expand Down
75 changes: 26 additions & 49 deletions internal/app/coroutines/rejectPromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
Id: req.RejectPromise.Id,
},
},
{
Kind: types.StoreReadSubscriptions,
ReadSubscriptions: &types.ReadSubscriptionsCommand{
PromiseIds: []string{req.RejectPromise.Id},
},
},
},
},
},
Expand All @@ -49,11 +43,8 @@
}

util.Assert(completion.Store != nil, "completion must not be nil")
util.Assert(len(completion.Store.Results) == 2, "completion must contain two results")

result := completion.Store.Results[0].ReadPromise
records := completion.Store.Results[1].ReadSubscriptions.Records

util.Assert(result.RowsReturned == 0 || result.RowsReturned == 1, "result must return 0 or 1 rows")

if result.RowsReturned == 0 {
Expand All @@ -73,7 +64,7 @@

if p.State == promise.Pending {
if t >= p.Timeout {
s.Add(TimeoutPromise(t, p, records, RejectPromise(t, req, res), func(t int64, err error) {
s.Add(TimeoutPromise(t, p, RejectPromise(t, req, res), func(t int64, err error) {

Check warning on line 67 in internal/app/coroutines/rejectPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/rejectPromise.go#L67

Added line #L67 was not covered by tests
if err != nil {
slog.Error("failed to timeout promise", "req", req, "err", err)
res(t, nil, err)
Expand Down Expand Up @@ -102,55 +93,41 @@
}, nil)
}))
} else {
commands := []*types.Command{
{
Kind: types.StoreUpdatePromise,
UpdatePromise: &types.UpdatePromiseCommand{
Id: req.RejectPromise.Id,
State: promise.Rejected,
Value: req.RejectPromise.Value,
CompletedOn: t,
},
},
{
Kind: types.StoreDeleteTimeout,
DeleteTimeout: &types.DeleteTimeoutCommand{
Id: req.RejectPromise.Id,
},
},
{
Kind: types.StoreDeleteSubscriptions,
DeleteSubscriptions: &types.DeleteSubscriptionsCommand{
PromiseId: req.RejectPromise.Id,
},
},
}

for _, record := range records {
commands = append(commands, &types.Command{
Kind: types.StoreCreateNotification,
CreateNotification: &types.CreateNotificationCommand{
Id: record.Id,
PromiseId: record.PromiseId,
Url: record.Url,
RetryPolicy: record.RetryPolicy,
Time: t,
},
})
}

submission := &types.Submission{
Kind: types.Store,
Store: &types.StoreSubmission{
Transaction: &types.Transaction{
Commands: commands,
Commands: []*types.Command{
{
Kind: types.StoreUpdatePromise,
UpdatePromise: &types.UpdatePromiseCommand{
Id: req.RejectPromise.Id,
State: promise.Rejected,
Value: req.RejectPromise.Value,
CompletedOn: t,
},
},
{
Kind: types.StoreCreateNotifications,
CreateNotifications: &types.CreateNotificationsCommand{
PromiseId: req.RejectPromise.Id,
Time: t,
},
},
{
Kind: types.StoreDeleteSubscriptions,
DeleteSubscriptions: &types.DeleteSubscriptionsCommand{
PromiseId: req.RejectPromise.Id,
},
},
},
},
},
}

c.Yield(submission, func(t int64, completion *types.Completion, err error) {
if err != nil {
slog.Error("failed to update state", "req", req, "err", err)
slog.Error("failed to update promise", "req", req, "err", err)

Check warning on line 130 in internal/app/coroutines/rejectPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/rejectPromise.go#L130

Added line #L130 was not covered by tests
res(t, nil, err)
return
}
Expand Down
Loading