-
Notifications
You must be signed in to change notification settings - Fork 138
User metadata #1657
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
User metadata #1657
Conversation
…es field to add a summary to an activity
| * General fixed details for this workflow execution that may appear in UI/CLI. | ||
| * This can be in Temporal markdown format and can span multiple lines. | ||
| * | ||
| * @experimental |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a short comment on all @experimental tags (see what we did elsewhere). Benefit isn't huge, but at least, it identifies which "feature" the experimental API is linked with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe i've done so in all the relevant places
| readonly options: ActivityOptions; | ||
| readonly headers: Headers; | ||
| readonly seq: number; | ||
| readonly cmdOpts?: WorkflowCommandOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should have this WorkflowCommandOptions type. I even wonder if we should inline summary and details directly in ActivityInput (without the extra UserMetadata nesting). Or add these two to ActivityOptions, though that might pose some minor challenge regarding the type provided to the proxyActivities() function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What did we do in other SDKs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically they are inline, I've changed it as such (aside from using ActivityOptions for summary/details for an activity, and TimerOptions as you suggested below)
packages/workflow/src/workflow.ts
Outdated
| * @param summary a short summary/description of the timer. Can serve as a timer ID. | ||
| */ | ||
| export function sleep(ms: Duration): Promise<void> { | ||
| export function sleep(ms: Duration, summary?: string): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried this will evolve badly. What if we then need to add description, and then other properties? Instead, I think I'd define a TimerOptions type, and take this as a second argument here. Then, we can easily add whatever properties we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what do we do in other SDKs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically we inline, but went with TimerOptions here given your reasoning
packages/workflow/src/workflow.ts
Outdated
| * @param summaries Record mapping activity names to their summary descriptions | ||
| * @returns A new proxy with the provided summaries | ||
| */ | ||
| withSummaries(summaries: Record<string, string>): ActivityInterfaceFor<A>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 That feels a bit awkward, and would prevent having an activity named withSummaries (ok, that's arguably very unlikely, but still means this approach would evolve badly).
I think we could get a better DX by using something similar to this, but at the activity-level rather than at the activities-level (mind the plural). That would also allow any extra option to be set at the call site, which is a recurring request.
For example, we could have:
const { echo } = proxyActivities<MyActivities>({ startToCloseTimeout: '5m' });
// No extra options
await echo(myArg1, myArg2);
// With extra options, higher order function style
await echo.withOptions({ summary: "..." })(myArg1, myArg2);
// Some other possible variants to be considered
await echo.withOptions({ summary: "..." }, myArg1, myArg2);
await echo.withOptions({ summary: "..." }, [myArg1, myArg2]);
I'll let you think you a bit about this, but we should probably include others in this discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opted for:
await echo.runWithOptions(options, args);
to allow users to override their default activity options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to executeWithOptions
|
also quickly added lazy decoding summary/details from workflow description can't do so (or at least annoying to do so) for schedule description because the description type has an invariant where the description must be a superclass of schedule options (which necessitate summary/details being strings) the alternative being to add new fields that lazily populate the existing fields, but that feels like poor ux |
packages/workflow/src/workflow.ts
Outdated
| startToFireTimeout: msToTs(durationMs), | ||
| }, | ||
| userMetadata: options && { | ||
| summary: options.summary ? activator.payloadConverter.toPayload(options.summary) : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if summary is an empty string? As it is now, it will be replaced by undefined. Not sure what would be the desired result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to keep empty strings, then it might be cleaner to use some toOptionalPayload helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if we don't care about empty strings, then should instead move the terniary out of this object:
userMetadata: options?.summary
? {
summary: activator.payloadConverter.toPayload(options.summary),
}
: undefined,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having an empty summary string replaced with undefined is reasonable. I don't see a reason why having an empty summary would be useful (or any more useful than undefined).
|
I believe there should also be user metadata on:
|
…ge to merge/override nested fields in objects (used to override activity options with activities' executeWithOptions), add metadata to child workflows and condition calls
Added for conditions and child workflows. Signals/updates/queries have a also going to mention this again, because it's been awhile |
mjameswh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointed out a few nits. Merge when ready.
Co-authored-by: James Watkins-Harvey <[email protected]>
What was changed
Added functionality for users to provide
staticDetailsandstaticSummarymetadata to workflow start commands.These can be retrieved via
describeon the workflow handler and are visibile via the UI/CLI.Users can set
currentDetails- a mutable details string within the workflow - viaSetCurrentDetailsand retrieve it viaGetCurrentDetails. This is visible via the UI/CLI and the__temporal_workflow_metadatainternal query.Users can add a
summary(short string description) when setting a timer and when starting an activity.A notable part of the change is the addition of
runWithOptionsto activities. Activities can now override their activity options at call time, like so:Closes [Feature Request] Support user metadata #1544
How was this tested:
Couple integration tests
Any docs updates needed?
Maybe