You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add `wf purge --all-filter-status` flag
Allow filtering by runtime status when purging workflow instances with
`--all-older-than`. This enables purging only instances in a specific
state (e.g., COMPLETED, FAILED, TERMINATED) rather than all terminal
instances. The flag is mutually exclusive with `--all` and requires
`--all-older-than` to be set.
Signed-off-by: joshvanl <me@joshvanl.dev>
* Review comments
Signed-off-by: joshvanl <me@joshvanl.dev>
* Adds review comments
Signed-off-by: joshvanl <me@joshvanl.dev>
---------
Signed-off-by: joshvanl <me@joshvanl.dev>
Co-authored-by: Cassie Coyle <cassie@diagrid.io>
Copy file name to clipboardExpand all lines: cmd/workflow/purge.go
+35-5Lines changed: 35 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -15,18 +15,21 @@ package workflow
15
15
16
16
import (
17
17
"errors"
18
+
"slices"
19
+
"strings"
18
20
19
21
"github.com/dapr/cli/pkg/workflow"
20
22
"github.com/dapr/kit/signals"
21
23
"github.com/spf13/cobra"
22
24
)
23
25
24
26
var (
25
-
flagPurgeOlderThanstring
26
-
flagPurgeAllbool
27
-
flagPurgeConn*connFlag
28
-
flagPurgeForcebool
29
-
schedulerNamespacestring
27
+
flagPurgeOlderThanstring
28
+
flagPurgeAllbool
29
+
flagPurgeConn*connFlag
30
+
flagPurgeForcebool
31
+
flagPurgeFilterStatusstring
32
+
schedulerNamespacestring
30
33
)
31
34
32
35
varPurgeCmd=&cobra.Command{
@@ -41,6 +44,9 @@ var PurgeCmd = &cobra.Command{
41
44
returnerrors.New("no arguments are accepted when using purge all flags")
42
45
}
43
46
default:
47
+
ifcmd.Flags().Changed("all-filter-status") {
48
+
returnerrors.New("--all-filter-status can only be used with --all-older-than")
49
+
}
44
50
iflen(args) ==0 {
45
51
returnerrors.New("one or more workflow instance ID arguments are required when not using purge all flags")
46
52
}
@@ -75,14 +81,38 @@ var PurgeCmd = &cobra.Command{
75
81
}
76
82
}
77
83
84
+
ifcmd.Flags().Changed("all-filter-status") {
85
+
opts.AllFilterStatus=&flagPurgeFilterStatus
86
+
}
87
+
78
88
returnworkflow.Purge(ctx, opts)
79
89
},
80
90
}
81
91
92
+
varpurgeFilterStatuses=workflow.RuntimeStatuses
93
+
82
94
funcinit() {
83
95
PurgeCmd.Flags().StringVar(&flagPurgeOlderThan, "all-older-than", "", "Purge workflow instances older than the specified Go duration or timestamp, e.g., '24h' or '2023-01-02T15:04:05Z'.")
84
96
PurgeCmd.Flags().BoolVar(&flagPurgeAll, "all", false, "Purge all workflow instances in a terminal state. Use with caution.")
97
+
PurgeCmd.Flags().StringVar(&flagPurgeFilterStatus, "all-filter-status", "", "Filter purge to only workflow instances with the given runtime status. Must be used with --all-older-than. One of "+strings.Join(purgeFilterStatuses, ", "))
returnerrors.New("--force is required when using --all-filter-status with a non-terminal status ("+flagPurgeFilterStatus+")")
109
+
}
110
+
}
111
+
ifpre!=nil {
112
+
returnpre(cmd, args)
113
+
}
114
+
returnnil
115
+
}
86
116
PurgeCmd.Flags().BoolVar(&flagPurgeForce, "force", false, "force will force a purge of a workflow, regardless of its current runtime state, or whether an active worker can process it, the backend will attempt to delete it anyway. This necessarily means the purging is executed out side of the workflow state machine, and therefore, can lead to corrupt state or broken workflow execution. Usage of this should _only_ be used when you know the workflow is not being currently processed. It is highly recommended to avoid using this flag unless absolutely necessary.")
87
117
88
118
PurgeCmd.Flags().StringVar(&schedulerNamespace, "scheduler-namespace", "dapr-system", "Kubernetes namespace where the scheduler is deployed, only relevant if --kubernetes is set")
0 commit comments