Skip to content

Commit

Permalink
User Metadata set on start / desc (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushisource authored Feb 27, 2025
1 parent aaded97 commit 728274a
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# Used by IDE
/.idea
/.vscode
/.zed
*~

4 changes: 4 additions & 0 deletions temporalcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ type SharedWorkflowStartOptions struct {
TaskTimeout Duration
SearchAttribute []string
Memo []string
StaticSummary string
StaticDetails string
}

func (v *SharedWorkflowStartOptions) buildFlags(cctx *CommandContext, f *pflag.FlagSet) {
Expand All @@ -206,6 +208,8 @@ func (v *SharedWorkflowStartOptions) buildFlags(cctx *CommandContext, f *pflag.F
f.Var(&v.TaskTimeout, "task-timeout", "Fail a Workflow Task if it lasts longer than `DURATION`. This is the Start-to-close timeout for a Workflow Task.")
f.StringArrayVar(&v.SearchAttribute, "search-attribute", nil, "Search Attribute in `KEY=VALUE` format. Keys must be identifiers, and values must be JSON values. For example: 'YourKey={\"your\": \"value\"}'. Can be passed multiple times.")
f.StringArrayVar(&v.Memo, "memo", nil, "Memo using 'KEY=\"VALUE\"' pairs. Use JSON values.")
f.StringVar(&v.StaticSummary, "static-summary", "", "Static Workflow summary for human consumption in UIs. Uses Temporal Markdown formatting, should be a single line.")
f.StringVar(&v.StaticDetails, "static-details", "", "Static Workflow details for human consumption in UIs. Uses Temporal Markdown formatting, may be multiple lines.")
}

type WorkflowStartOptions struct {
Expand Down
2 changes: 2 additions & 0 deletions temporalcli/commands.schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ func toScheduleAction(sw *SharedWorkflowStartOptions, i *PayloadInputOptions) (c
// RetryPolicy not supported yet
UntypedSearchAttributes: untypedSearchAttributes,
Memo: opts.Memo,
StaticSummary: opts.StaticSummary,
StaticDetails: opts.StaticDetails,
}
if action.Args, err = i.buildRawInput(); err != nil {
return nil, err
Expand Down
18 changes: 18 additions & 0 deletions temporalcli/commands.schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ func (s *SharedServerSuite) TestSchedule_CreateDescribe_SearchAttributes_Memo()
s.ContainsOnSameLine(out, "Action", "wfMemo", b64(`"other data"`))
}

func (s *SharedServerSuite) TestSchedule_CreateDescribe_UserMetadata() {
schedId, _, res := s.createSchedule("--interval", "10d",
"--static-summary", "summ",
"--static-details", "details",
)
s.NoError(res.Err)

res = s.Execute(
"schedule", "describe",
"--address", s.Address(),
"-s", schedId,
)
s.NoError(res.Err)
out := res.Stdout.String()
s.ContainsOnSameLine(out, "Action", "Summary", "summ")
s.ContainsOnSameLine(out, "Action", "Details", "details")
}

func (s *SharedServerSuite) TestSchedule_List() {
res := s.Execute(
"operator", "search-attribute", "create",
Expand Down
2 changes: 2 additions & 0 deletions temporalcli/commands.workflow_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ func buildStartOptions(sw *SharedWorkflowStartOptions, w *WorkflowStartOptions)
CronSchedule: w.Cron,
WorkflowExecutionErrorWhenAlreadyStarted: w.FailExisting,
StartDelay: w.StartDelay.Duration(),
StaticSummary: sw.StaticSummary,
StaticDetails: sw.StaticDetails,
}
if w.IdReusePolicy.Value != "" {
var err error
Expand Down
14 changes: 14 additions & 0 deletions temporalcli/commands.workflow_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ func (c *TemporalWorkflowDescribeCommand) run(cctx *CommandContext, args []strin
HistorySize: info.HistorySizeBytes,
}, printer.StructuredOptions{})

staticSummary := resp.GetExecutionConfig().GetUserMetadata().GetSummary()
staticDetails := resp.GetExecutionConfig().GetUserMetadata().GetDetails()
if len(staticSummary.GetData()) > 0 || len(staticDetails.GetData()) > 0 {
cctx.Printer.Println()
cctx.Printer.Println(color.MagentaString("Metadata:"))
_ = cctx.Printer.PrintStructured(struct {
StaticSummary *common.Payload
StaticDetails *common.Payload
}{
StaticSummary: staticSummary,
StaticDetails: staticDetails,
}, printer.StructuredOptions{})
}

if info.VersioningInfo != nil {
cctx.Printer.Println()
cctx.Printer.Println(color.MagentaString("Versioning Info:"))
Expand Down
43 changes: 43 additions & 0 deletions temporalcli/commands.workflow_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,3 +950,46 @@ func (s *SharedServerSuite) Test_WorkflowResult() {
s.Contains(output, `"message": "failed on purpose"`)
s.Contains(output, "workflowExecutionFailedEventAttributes")
}

func (s *SharedServerSuite) TestWorkflow_Describe_WorkflowMetadata() {
workflowId := uuid.NewString()

s.Worker().OnDevWorkflow(func(ctx workflow.Context, input any) (any, error) {
return map[string]string{"foo": "bar"}, nil
})

res := s.Execute(
"workflow", "start",
"--address", s.Address(),
"--task-queue", s.Worker().Options.TaskQueue,
"--type", "DevWorkflow",
"--workflow-id", workflowId,
"--static-summary", "summie",
"--static-details", "deets",
)
s.NoError(res.Err)

// Text
res = s.Execute(
"workflow", "describe",
"--address", s.Address(),
"-w", workflowId,
)
s.NoError(res.Err)
out := res.Stdout.String()
s.ContainsOnSameLine(out, "StaticSummary", "summie")
s.ContainsOnSameLine(out, "StaticDetails", "deets")

// JSON
res = s.Execute(
"workflow", "describe",
"-o", "json",
"--address", s.Address(),
"-w", workflowId,
)
s.NoError(res.Err)
var jsonOut workflowservice.DescribeWorkflowExecutionResponse
s.NoError(temporalcli.UnmarshalProtoJSONWithOptions(res.Stdout.Bytes(), &jsonOut, true))
s.NotNil(jsonOut.ExecutionConfig.UserMetadata.Summary)
s.NotNil(jsonOut.ExecutionConfig.UserMetadata.Details)
}
12 changes: 12 additions & 0 deletions temporalcli/commandsgen/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3991,6 +3991,18 @@ option-sets:
description: |
Memo using 'KEY="VALUE"' pairs.
Use JSON values.
- name: static-summary
type: string
experimental: true
description: |
Static Workflow summary for human consumption in UIs.
Uses Temporal Markdown formatting, should be a single line.
- name: static-details
type: string
experimental: true
description: |
Static Workflow details for human consumption in UIs.
Uses Temporal Markdown formatting, may be multiple lines.
- name: workflow-start
options:
Expand Down

0 comments on commit 728274a

Please # to comment.