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

Add UpsertMemo API #883

Merged
merged 8 commits into from
Sep 7, 2022
Merged

Conversation

rodrigozhou
Copy link
Contributor

@rodrigozhou rodrigozhou commented Aug 15, 2022

What was changed

Adding an API for UpsertMemo. It merges with current memo and creates a command ModifyWorkflowProperties with the updated memo.
This change depends on temporalio/api#218.

Why?

Feature request: temporalio/features#119

Checklist

  1. How was this tested:
    • Created new tests.

internal/internal_event_handlers.go Outdated Show resolved Hide resolved
internal/internal_event_handlers.go Outdated Show resolved Hide resolved
func mergeMemo(current, upsert *commonpb.Memo) *commonpb.Memo {
if current == nil || len(current.Fields) == 0 {
if upsert == nil || len(upsert.Fields) == 0 {
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an empty memo was on workflow info, this has now made it nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, the new memo cannot be nil or an empty map. See validateAndSerializeMemo which is executed before merging the memo.

}

func mergeMemo(current, upsert *commonpb.Memo) *commonpb.Memo {
if current == nil || len(current.Fields) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also just len(current.GetFields()) == 0

test/integration_test.go Show resolved Hide resolved
@bergundy
Copy link
Member

Didn't look at the code but something I wish we'd done with search attributes in TS is delay sending the command until the end of an "activation", so if a user calls UpsertMemo({ a: 1 }); UpsertMemo({ b: 2 }); UpsertMemo({ a: 2 }) the SDK would only issue 1 UpsertMemo({ a: 2, b: 2}) command.

@bergundy
Copy link
Member

@rodrigozhou note that I moved the original issue to sdk-features and marked this PR as not closing for that issue, we need to implement in all SDKs.

@rodrigozhou
Copy link
Contributor Author

rodrigozhou commented Aug 30, 2022

The CI failure is because the CI used the docker-compose repo to start the temporal server, which doesn't include UpsertMemo yet. Locally, all tests passes.

EDIT: skipped UpsertMemo tests for now

test/integration_test.go Outdated Show resolved Hide resolved
test/integration_test.go Outdated Show resolved Hide resolved
Comment on lines +1452 to +1454
if strictMode && !isMemoMatched(eventAttributes.UpsertedMemo, commandAttributes.UpsertedMemo) {
return false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StrictMode was there for historical reason. But I don't think they are needed anymore. We probably should remove strictMode. @cretz
(No change requested for this PR.)

@rodrigozhou rodrigozhou enabled auto-merge (squash) September 7, 2022 17:29
@rodrigozhou rodrigozhou disabled auto-merge September 7, 2022 17:35
@rodrigozhou rodrigozhou merged commit 9341009 into temporalio:master Sep 7, 2022
@rodrigozhou rodrigozhou deleted the upsert-memo branch September 7, 2022 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants