Skip to content
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

Add temporal workflow fix-history-json subcommand. #504

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions temporalcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ func NewTemporalWorkflowCommand(cctx *CommandContext, parent *TemporalCommand) *
s.Command.AddCommand(&NewTemporalWorkflowDeleteCommand(cctx, &s).Command)
s.Command.AddCommand(&NewTemporalWorkflowDescribeCommand(cctx, &s).Command)
s.Command.AddCommand(&NewTemporalWorkflowExecuteCommand(cctx, &s).Command)
s.Command.AddCommand(&NewTemporalWorkflowFixHistoryJsonCommand(cctx, &s).Command)
s.Command.AddCommand(&NewTemporalWorkflowListCommand(cctx, &s).Command)
s.Command.AddCommand(&NewTemporalWorkflowQueryCommand(cctx, &s).Command)
s.Command.AddCommand(&NewTemporalWorkflowResetCommand(cctx, &s).Command)
Expand Down Expand Up @@ -1457,6 +1458,36 @@ func NewTemporalWorkflowExecuteCommand(cctx *CommandContext, parent *TemporalWor
return &s
}

type TemporalWorkflowFixHistoryJsonCommand struct {
Parent *TemporalWorkflowCommand
Command cobra.Command
Source string
Target string
}

func NewTemporalWorkflowFixHistoryJsonCommand(cctx *CommandContext, parent *TemporalWorkflowCommand) *TemporalWorkflowFixHistoryJsonCommand {
var s TemporalWorkflowFixHistoryJsonCommand
s.Parent = parent
s.Command.DisableFlagsInUseLine = true
s.Command.Use = "fix-history-json [flags]"
s.Command.Short = "Updates an event history JSON file to the current format."
if hasHighlighting {
s.Command.Long = "\x1b[1mtemporal workflow fix-history-json \\\n\t--source original.json \\\n\t--target reserialized.json\x1b[0m\n\nUse the options listed below to change the command's behavior."
} else {
s.Command.Long = "```\ntemporal workflow fix-history-json \\\n\t--source original.json \\\n\t--target reserialized.json\n```\n\nUse the options listed below to change the command's behavior."
}
s.Command.Args = cobra.NoArgs
s.Command.Flags().StringVarP(&s.Source, "source", "s", "", "Path to the input file.")
_ = cobra.MarkFlagRequired(s.Command.Flags(), "source")
s.Command.Flags().StringVarP(&s.Target, "target", "t", "", "Path to the output file, or standard output if not set.")
s.Command.Run = func(c *cobra.Command, args []string) {
if err := s.run(cctx, args); err != nil {
cctx.Options.Fail(err)
}
}
return &s
}

type TemporalWorkflowListCommand struct {
Parent *TemporalWorkflowCommand
Command cobra.Command
Expand Down
37 changes: 37 additions & 0 deletions temporalcli/commands.workflow_fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package temporalcli

import (
"bytes"
"os"

"go.temporal.io/sdk/client"
"google.golang.org/protobuf/encoding/protojson"
)

func (c *TemporalWorkflowFixHistoryJsonCommand) run(cctx *CommandContext, args []string) error {
raw, err := os.ReadFile(c.Source)
if err != nil {
return err
}

hjo := client.HistoryJSONOptions{}
history, err := client.HistoryFromJSON(bytes.NewReader(raw), hjo)
if err != nil {
return err
}

mo := protojson.MarshalOptions{Indent: " "}
raw, err = mo.Marshal(history)
if err != nil {
return err
}

switch c.Target {
case "", "-":
_, err = cctx.Options.Stdout.Write(raw)
return err

default:
return os.WriteFile(c.Target, raw, 0o666)
}
}
15 changes: 15 additions & 0 deletions temporalcli/commandsmd/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,21 @@ temporal workflow execute
Includes options set for [workflow start](#options-set-for-workflow-start).
Includes options set for [payload input](#options-set-for-payload-input).

### temporal workflow fix-history-json: Updates an event history JSON file to the current format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this naming. I hope we can remove it one day, heh.


```
temporal workflow fix-history-json \
--source original.json \
--target reserialized.json
```

Use the options listed below to change the command's behavior.

#### Options

* `--source`, `-s` (string) - Path to the input file. Required.
* `--target`, `-t` (string) - Path to the output file, or standard output if not set.

### temporal workflow list: List Workflow Executions based on a Query.

The `temporal workflow list` command provides a list of [Workflow Executions](/concepts/what-is-a-workflow-execution)
Expand Down
Loading