Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions internal/temporalcli/commands.schedule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package temporalcli

import (
"encoding/json"
"errors"
"fmt"
"regexp"
Expand All @@ -16,6 +17,7 @@ import (
commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
schedpb "go.temporal.io/api/schedule/v1"
"go.temporal.io/api/temporalproto"
"go.temporal.io/api/workflowservice/v1"
"go.temporal.io/sdk/client"
)
Expand Down Expand Up @@ -48,8 +50,8 @@ type printableSchedule struct {
LastUpdateAt time.Time `cli:",cardOmitEmpty"` // describe only
ActionCounts *actionCounts `cli:",cardOmitEmpty"` // describe only
// SearchAttributes, Memo
SearchAttributes *commonpb.SearchAttributes `cli:",cardOmitEmpty"`
Memo *commonpb.Memo `cli:",cardOmitEmpty"`
SearchAttributes map[string]interface{} `cli:",cardOmitEmpty"`
Memo *commonpb.Memo `cli:",cardOmitEmpty"`
}

type actionCounts struct {
Expand All @@ -69,7 +71,7 @@ func describeResultToPrintable(id string, desc *client.ScheduleDescription) *pri
// ID, SearchAttributes, Memo
out := &printableSchedule{
ScheduleId: id,
SearchAttributes: desc.SearchAttributes,
SearchAttributes: searchAttributesToMap(desc.SearchAttributes),
Memo: desc.Memo,
}
// Schedule.Action
Expand Down Expand Up @@ -114,7 +116,7 @@ func listEntryToPrintable(ent *client.ScheduleListEntry) *printableSchedule {
Paused: ent.Paused,
Notes: ent.Note,
Action: struct{ Workflow string }{Workflow: ent.WorkflowType.Name},
SearchAttributes: ent.SearchAttributes,
SearchAttributes: searchAttributesToMap(ent.SearchAttributes),
Memo: ent.Memo,
}
specToPrintable(out, ent.Spec)
Expand Down Expand Up @@ -640,3 +642,21 @@ func (c *TemporalScheduleListMatchingTimesCommand) run(cctx *CommandContext, arg
Table: &printer.TableOptions{},
})
}

func searchAttributesToMap(sa *commonpb.SearchAttributes) map[string]interface{} {
// Step 1 — handle nil
if sa == nil {
return nil
}
// Step 2 — marshal to JSON bytes using proto marshaler
b, err := temporalproto.CustomJSONMarshalOptions{}.Marshal(sa)
if err != nil {
return nil
}
// Step 3 — unmarshal bytes into plain map
var m map[string]interface{}
if err := json.Unmarshal(b, &m); err != nil {
return nil
}
return m
}