Skip to content
Open
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
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,12 @@ func isLoadSettings(cmd *cobra.Command) bool {
"cre workflow limits export": {},
"cre workflow build": {},
"cre workflow list": {},
"cre workflow execution": {},
"cre workflow execution list": {},
"cre workflow execution status": {},
"cre workflow execution events": {},
"cre workflow execution logs": {},
"cre workflow status": {},
"cre account": {},
"cre secrets": {},
"cre templates": {},
Expand Down
8 changes: 8 additions & 0 deletions cmd/workflow/deploy/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ func (h *handler) handleUpsert(ctx context.Context, params client.RegisterWorkfl
if h.inputs.ConfigURL != nil && *h.inputs.ConfigURL != "" {
ui.Dim(fmt.Sprintf(" Config URL: %s", *h.inputs.ConfigURL))
}
ui.Line()
ui.Bold("Next steps:")
ui.Dim(" cre workflow list")
ui.Dim(fmt.Sprintf(" cre workflow execution list %s", workflowName))
ui.Dim(fmt.Sprintf(" cre workflow execution list %s --status FAILURE", workflowName))
ui.Dim(" cre workflow execution status <execution-id>")
ui.Dim(" cre workflow execution events <execution-id>")
ui.Dim(" cre workflow execution logs <execution-id>")

case client.Raw:
ui.Line()
Expand Down
8 changes: 8 additions & 0 deletions cmd/workflow/deploy/registry_deploy_strategy_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ func (a *privateRegistryDeployStrategy) Upsert(ctx context.Context) error {
if result.Owner != "" {
ui.Dim(fmt.Sprintf(" Owner: %s", result.Owner))
}
ui.Line()
ui.Bold("Next steps:")
ui.Dim(" cre workflow list")
ui.Dim(fmt.Sprintf(" cre workflow execution list %s", result.WorkflowName))
ui.Dim(fmt.Sprintf(" cre workflow execution list %s --status FAILURE", result.WorkflowName))
ui.Dim(" cre workflow execution status <execution-id>")
ui.Dim(" cre workflow execution events <execution-id>")
ui.Dim(" cre workflow execution logs <execution-id>")

return nil
}
Expand Down
118 changes: 118 additions & 0 deletions cmd/workflow/execution/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package execution

import (
"context"
"fmt"

"github.com/spf13/cobra"

"github.com/smartcontractkit/cre-cli/internal/client/graphqlclient"
"github.com/smartcontractkit/cre-cli/internal/client/workflowdataclient"
"github.com/smartcontractkit/cre-cli/internal/credentials"
"github.com/smartcontractkit/cre-cli/internal/runtime"
"github.com/smartcontractkit/cre-cli/internal/ui"
"github.com/smartcontractkit/cre-cli/internal/workflowrender"
)

type EventsInputs struct {
ExecutionUUID string
CapabilityID *string
Status *string
OutputFormat string
}

type EventsHandler struct {
credentials *credentials.Credentials
wdc *workflowdataclient.Client
}

func NewEventsHandler(ctx *runtime.Context) *EventsHandler {
gql := graphqlclient.New(ctx.Credentials, ctx.EnvironmentSet, ctx.Logger)
wdc := workflowdataclient.New(gql, ctx.Logger)
return &EventsHandler{credentials: ctx.Credentials, wdc: wdc}
}

func NewEventsHandlerWithClient(ctx *runtime.Context, wdc *workflowdataclient.Client) *EventsHandler {
return &EventsHandler{credentials: ctx.Credentials, wdc: wdc}
}

func resolveEventsInputs(executionUUID, capabilityID, status, outputFormat string, jsonFlag bool) (EventsInputs, error) {
if jsonFlag {
outputFormat = outputFormatJSON
}
if outputFormat != "" && outputFormat != outputFormatJSON {
return EventsInputs{}, fmt.Errorf("--output %q is not supported; only %q is accepted", outputFormat, outputFormatJSON)
}
in := EventsInputs{
ExecutionUUID: executionUUID,
OutputFormat: outputFormat,
}
if capabilityID != "" {
in.CapabilityID = &capabilityID
}
if status != "" {
in.Status = &status
}
return in, nil
}

func (h *EventsHandler) Execute(ctx context.Context, in EventsInputs) error {
if h.credentials == nil {
return fmt.Errorf("credentials not available — run `cre login` and retry")
}

uuid, err := resolveExecutionUUID(ctx, h.wdc, in.ExecutionUUID)
if err != nil {
return err
}

spinner := ui.NewSpinner()
spinner.Start("Fetching execution events...")
events, err := h.wdc.ListExecutionEvents(ctx, workflowdataclient.ListEventsInput{
ExecutionUUID: uuid,
CapabilityID: in.CapabilityID,
Status: in.Status,
})
spinner.Stop()
if err != nil {
return err
}

if in.OutputFormat == outputFormatJSON {
return workflowrender.PrintEventsJSON(events)
}
workflowrender.PrintEventsTable(events)
return nil
}

func newEvents(runtimeContext *runtime.Context) *cobra.Command {
var capabilityID string
var status string
var outputFormat string
var jsonFlag bool

cmd := &cobra.Command{
Use: "events <execution-uuid>",
Short: "Show the node/capability event timeline for an execution",
Long: `Fetch and display the ordered sequence of capability events for a workflow
execution, including per-event status, method, duration, and any errors.`,
Example: "cre workflow execution events 7f3d8a12-b1c2-4d3e-9f0a-1b2c3d4e5f6g\n" +
" cre workflow execution events 7f3d8a12-b1c2-4d3e-9f0a-1b2c3d4e5f6g --capability fetch-price\n" +
" cre workflow execution events 7f3d8a12-b1c2-4d3e-9f0a-1b2c3d4e5f6g --status FAILURE\n" +
" cre workflow execution events 7f3d8a12-b1c2-4d3e-9f0a-1b2c3d4e5f6g --output json",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
in, err := resolveEventsInputs(args[0], capabilityID, status, outputFormat, jsonFlag)
if err != nil {
return err
}
return NewEventsHandler(runtimeContext).Execute(cmd.Context(), in)
},
}

cmd.Flags().StringVar(&capabilityID, "capability", "", "Filter events to a specific capability ID")
cmd.Flags().StringVar(&status, "status", "", "Filter events by status (e.g. FAILURE)")
cmd.Flags().StringVar(&outputFormat, "output", "", `Output format: "json" prints a JSON array to stdout`)
cmd.Flags().BoolVar(&jsonFlag, "json", false, "Output as JSON (shorthand for --output=json)")
return cmd
}
23 changes: 23 additions & 0 deletions cmd/workflow/execution/execution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package execution

import (
"github.com/spf13/cobra"

"github.com/smartcontractkit/cre-cli/internal/runtime"
)

// New returns the `execution` subcommand group wired under `cre workflow`.
func New(runtimeContext *runtime.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "execution",
Short: "Query workflow execution history",
Long: `The execution command provides visibility into workflow executions, node events, and logs.`,
}

cmd.AddCommand(newList(runtimeContext))
cmd.AddCommand(newStatus(runtimeContext))
cmd.AddCommand(newEvents(runtimeContext))
cmd.AddCommand(newLogs(runtimeContext))

return cmd
}
Loading
Loading