Skip to content

Commit

Permalink
Expose user metadata fields on scheduling workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushisource committed Jan 17, 2025
1 parent 1c6e01b commit 925c6f0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
30 changes: 25 additions & 5 deletions internal/internal_schedule_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ func (scheduleHandle *scheduleHandleImpl) Update(ctx context.Context, options Sc
if err != nil {
return err
}
scheduleDescription, err := scheduleDescriptionFromPB(scheduleHandle.client.logger, describeResponse)
scheduleDescription, err := scheduleDescriptionFromPB(
scheduleHandle.client.logger, scheduleHandle.client.dataConverter, describeResponse)
if err != nil {
return err
}
Expand Down Expand Up @@ -327,7 +328,8 @@ func (scheduleHandle *scheduleHandleImpl) Describe(ctx context.Context) (*Schedu
if err != nil {
return nil, err
}
return scheduleDescriptionFromPB(scheduleHandle.client.logger, describeResponse)
return scheduleDescriptionFromPB(
scheduleHandle.client.logger, scheduleHandle.client.dataConverter, describeResponse)
}

func (scheduleHandle *scheduleHandleImpl) Trigger(ctx context.Context, options ScheduleTriggerOptions) error {
Expand Down Expand Up @@ -469,6 +471,7 @@ func convertFromPBScheduleSpec(scheduleSpec *schedulepb.ScheduleSpec) *ScheduleS

func scheduleDescriptionFromPB(
logger log.Logger,
dc converter.DataConverter,
describeResponse *workflowservice.DescribeScheduleResponse,
) (*ScheduleDescription, error) {
if describeResponse == nil {
Expand All @@ -490,7 +493,7 @@ func scheduleDescriptionFromPB(
nextActionTimes[i] = t.AsTime()
}

actionDescription, err := convertFromPBScheduleAction(logger, describeResponse.Schedule.Action)
actionDescription, err := convertFromPBScheduleAction(logger, dc, describeResponse.Schedule.Action)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -637,7 +640,7 @@ func convertToPBScheduleAction(
return nil, err
}

userMetadata, err := buildUserMetadata(action.staticSummary, action.staticDetails, dataConverter)
userMetadata, err := buildUserMetadata(action.StaticSummary, action.StaticDetails, dataConverter)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -667,7 +670,11 @@ func convertToPBScheduleAction(
}
}

func convertFromPBScheduleAction(logger log.Logger, action *schedulepb.ScheduleAction) (ScheduleAction, error) {
func convertFromPBScheduleAction(
logger log.Logger,
dc converter.DataConverter,
action *schedulepb.ScheduleAction,
) (ScheduleAction, error) {
switch action := action.Action.(type) {
case *schedulepb.ScheduleAction_StartWorkflow:
workflow := action.StartWorkflow
Expand Down Expand Up @@ -697,6 +704,17 @@ func convertFromPBScheduleAction(logger log.Logger, action *schedulepb.ScheduleA
}
}

var convertedSummary *string = new(string)
err := dc.FromPayload(workflow.GetUserMetadata().GetSummary(), convertedSummary)
if err != nil {
return nil, fmt.Errorf("could not decode user metadata summary: %w", err)
}
var convertedDetails *string = new(string)
err = dc.FromPayload(workflow.GetUserMetadata().GetDetails(), convertedDetails)
if err != nil {
return nil, fmt.Errorf("could not decode user metadata details: %w", err)
}

return &ScheduleWorkflowAction{
ID: workflow.GetWorkflowId(),
Workflow: workflow.WorkflowType.GetName(),
Expand All @@ -710,6 +728,8 @@ func convertFromPBScheduleAction(logger log.Logger, action *schedulepb.ScheduleA
TypedSearchAttributes: searchAttrs,
UntypedSearchAttributes: untypedSearchAttrs,
VersioningOverride: versioningOverrideFromProto(workflow.VersioningOverride),
StaticSummary: *convertedSummary,
StaticDetails: *convertedDetails,
}, nil
default:
// TODO maybe just panic instead?
Expand Down
19 changes: 16 additions & 3 deletions internal/schedule_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,22 @@ type (
// NOTE: Experimental
VersioningOverride VersioningOverride

// TODO(cretz): Expose once https://github.com/temporalio/temporal/issues/6412 is fixed
staticSummary string
staticDetails string
// StaticSummary is a single-line fixed summary for this child workflow execution that will appear in UI/CLI. This can be
// in single-line Temporal Markdown format.
//
// Optional: defaults to none/empty.
//
// NOTE: Experimental
StaticSummary string

// Details - General fixed details for this child workflow execution that will appear in UI/CLI. This can be in
// Temporal markdown format and can span multiple lines. This is a fixed value on the workflow that cannot be
// updated. For details that can be updated, use SetCurrentDetails within the workflow.
//
// Optional: defaults to none/empty.
//
// NOTE: Experimental
StaticDetails string
}

// ScheduleOptions configure the parameters for creating a schedule.
Expand Down
4 changes: 4 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5544,6 +5544,8 @@ func (ts *IntegrationTestSuite) TestScheduleDescribeState() {
TaskQueue: ts.taskQueueName,
WorkflowExecutionTimeout: 15 * time.Second,
WorkflowTaskTimeout: time.Second,
StaticSummary: "summy",
StaticDetails: "deets",
},
Overlap: enumspb.SCHEDULE_OVERLAP_POLICY_SKIP,
CatchupWindow: time.Minute,
Expand Down Expand Up @@ -5578,6 +5580,8 @@ func (ts *IntegrationTestSuite) TestScheduleDescribeState() {
ts.Equal("TwoParameterWorkflow", action.Workflow)
ts.Equal(expectedArg1Value, action.Args[0])
ts.Equal(expectedArg2Value, action.Args[1])
ts.Equal("summy", action.StaticSummary)
ts.Equal("deets", action.StaticDetails)
default:
ts.Fail("schedule action wrong type")
}
Expand Down

0 comments on commit 925c6f0

Please sign in to comment.