Skip to content

Commit

Permalink
scripts: keystone: Add utility to delete a workflow spec
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Jul 12, 2024
1 parent 750cf0d commit d6986f7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/scripts/keystone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
src.NewDeleteJobsCommand(),
src.NewDeployAndInitializeCapabilitiesRegistryCommand(),
src.NewDeployWorkflowsCommand(),
src.NewDeleteWorkflowsCommand(),
}

commandsList := func(commands []command) string {
Expand Down
5 changes: 5 additions & 0 deletions core/scripts/keystone/src/04_delete_ocr3_jobs_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ type BootSpec struct {
ContractID string
}

type WorkflowSpec struct {
WorkflowID string
}

type JobSpec struct {
Id string
Name string
BootstrapSpec BootSpec
OffChainReporting2OracleSpec OCRSpec
WorkflowSpec WorkflowSpec
}

func NewDeleteJobsCommand() *deleteJobs {
Expand Down
61 changes: 61 additions & 0 deletions core/scripts/keystone/src/07_delete_workflows_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package src

import (
"bytes"
"encoding/json"
"flag"
"fmt"

"github.com/urfave/cli"

helpers "github.com/smartcontractkit/chainlink/core/scripts/common"
)

type deleteWorkflows struct {
}

func NewDeleteWorkflowsCommand() *deleteWorkflows {
return &deleteWorkflows{}
}

func (g *deleteWorkflows) Name() string {
return "delete-workflows"
}

func (g *deleteWorkflows) Run(args []string) {
nodes := downloadNodeAPICredentials(".cache/NodeList.txt")

for _, node := range nodes {
output := &bytes.Buffer{}
client, app := newApp(node, output)

fmt.Println("Logging in:", node.url)
loginFs := flag.NewFlagSet("test", flag.ContinueOnError)
loginFs.Bool("bypass-version-check", true, "")
loginCtx := cli.NewContext(app, loginFs, nil)
err := client.RemoteLogin(loginCtx)
helpers.PanicErr(err)
output.Reset()

fileFs := flag.NewFlagSet("test", flag.ExitOnError)
err = client.ListJobs(cli.NewContext(app, fileFs, nil))
helpers.PanicErr(err)

var parsed []JobSpec
err = json.Unmarshal(output.Bytes(), &parsed)
helpers.PanicErr(err)

for _, jobSpec := range parsed {
if jobSpec.WorkflowSpec.WorkflowID != "" {
fmt.Println("Deleting workflow job ID:", jobSpec.Id, "name:", jobSpec.Name)
set := flag.NewFlagSet("test", flag.ExitOnError)
err = set.Parse([]string{jobSpec.Id})
helpers.PanicErr(err)
err = client.DeleteJob(cli.NewContext(app, set, nil))
helpers.PanicErr(err)
}
}

output.Reset()
}
}

0 comments on commit d6986f7

Please sign in to comment.