From 925c6f0672d3f02ad18250bafd118d6f53d5efb6 Mon Sep 17 00:00:00 2001 From: Spencer Judge Date: Fri, 17 Jan 2025 10:44:15 -0800 Subject: [PATCH] Expose user metadata fields on scheduling workflows --- internal/internal_schedule_client.go | 30 +++++++++++++++++++++++----- internal/schedule_client.go | 19 +++++++++++++++--- test/integration_test.go | 4 ++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/internal/internal_schedule_client.go b/internal/internal_schedule_client.go index f96802454..9e6d3a82e 100644 --- a/internal/internal_schedule_client.go +++ b/internal/internal_schedule_client.go @@ -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 } @@ -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 { @@ -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 { @@ -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 } @@ -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 } @@ -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 @@ -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(), @@ -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? diff --git a/internal/schedule_client.go b/internal/schedule_client.go index 0b2b0bfc2..c0fd694d7 100644 --- a/internal/schedule_client.go +++ b/internal/schedule_client.go @@ -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. diff --git a/test/integration_test.go b/test/integration_test.go index 4f2fcc7e9..fd6c99761 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -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, @@ -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") }