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

fix: worker: add all tasks flag #10232

Merged
merged 7 commits into from
Feb 10, 2023
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
55 changes: 42 additions & 13 deletions cmd/lotus-worker/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,53 @@ var settableStr = func() string {
var tasksEnableCmd = &cli.Command{
Name: "enable",
Usage: "Enable a task type",
ArgsUsage: "[" + settableStr + "]",
Action: taskAction(api.Worker.TaskEnable),
ArgsUsage: "--all | [" + settableStr + "]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "Enable all task types",
},
},
Action: taskAction(api.Worker.TaskEnable),
}

var tasksDisableCmd = &cli.Command{
Name: "disable",
Usage: "Disable a task type",
ArgsUsage: "[" + settableStr + "]",
Action: taskAction(api.Worker.TaskDisable),
ArgsUsage: "--all | [" + settableStr + "]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "Disable all task types",
},
},
Action: taskAction(api.Worker.TaskDisable),
}

func taskAction(tf func(a api.Worker, ctx context.Context, tt sealtasks.TaskType) error) func(cctx *cli.Context) error {
return func(cctx *cli.Context) error {
if cctx.NArg() != 1 {
return xerrors.Errorf("expected 1 argument")
allFlag := cctx.Bool("all")

if cctx.NArg() == 1 && allFlag {
return xerrors.Errorf("Cannot use --all flag with task type argument")
}

if cctx.NArg() != 1 && !allFlag {
return xerrors.Errorf("Expected 1 argument or use --all flag")
}

var tt sealtasks.TaskType
for taskType := range allowSetting {
if taskType.Short() == cctx.Args().First() {
tt = taskType
break
if cctx.NArg() == 1 {
for taskType := range allowSetting {
if taskType.Short() == cctx.Args().First() {
tt = taskType
break
}
}
}

if tt == "" {
return xerrors.Errorf("unknown task type '%s'", cctx.Args().First())
if tt == "" {
return xerrors.Errorf("unknown task type '%s'", cctx.Args().First())
}
}

api, closer, err := lcli.GetWorkerAPI(cctx)
Expand All @@ -81,6 +101,15 @@ func taskAction(tf func(a api.Worker, ctx context.Context, tt sealtasks.TaskType

ctx := lcli.ReqContext(cctx)

if allFlag {
for taskType := range allowSetting {
if err := tf(api, ctx, taskType); err != nil {
return err
}
}
return nil
}

return tf(api, ctx, tt)
}
}
8 changes: 4 additions & 4 deletions documentation/en/cli-lotus-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ NAME:
lotus-worker tasks enable - Enable a task type

USAGE:
lotus-worker tasks enable [command options] [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK]
lotus-worker tasks enable [command options] --all | [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK]

OPTIONS:
--help, -h show help (default: false)
--all Enable all task types (default: false)

```

Expand All @@ -231,9 +231,9 @@ NAME:
lotus-worker tasks disable - Disable a task type

USAGE:
lotus-worker tasks disable [command options] [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK]
lotus-worker tasks disable [command options] --all | [UNS|C2|PC2|PC1|PR2|RU|AP|DC|GSK]

OPTIONS:
--help, -h show help (default: false)
--all Disable all task types (default: false)

```