2020-11-26 16:33:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
|
|
|
)
|
|
|
|
|
|
|
|
var tasksCmd = &cli.Command{
|
|
|
|
Name: "tasks",
|
|
|
|
Usage: "Manage task processing",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
tasksEnableCmd,
|
|
|
|
tasksDisableCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var allowSetting = map[sealtasks.TaskType]struct{}{
|
2022-02-14 18:28:49 +00:00
|
|
|
sealtasks.TTAddPiece: {},
|
2022-04-26 16:22:52 +00:00
|
|
|
sealtasks.TTDataCid: {},
|
2022-02-14 18:28:49 +00:00
|
|
|
sealtasks.TTPreCommit1: {},
|
|
|
|
sealtasks.TTPreCommit2: {},
|
|
|
|
sealtasks.TTCommit2: {},
|
|
|
|
sealtasks.TTUnseal: {},
|
|
|
|
sealtasks.TTReplicaUpdate: {},
|
|
|
|
sealtasks.TTProveReplicaUpdate2: {},
|
|
|
|
sealtasks.TTRegenSectorKey: {},
|
2020-11-26 16:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var settableStr = func() string {
|
|
|
|
var s []string
|
|
|
|
for _, tt := range ttList(allowSetting) {
|
|
|
|
s = append(s, tt.Short())
|
|
|
|
}
|
|
|
|
return strings.Join(s, "|")
|
|
|
|
}()
|
|
|
|
|
|
|
|
var tasksEnableCmd = &cli.Command{
|
|
|
|
Name: "enable",
|
|
|
|
Usage: "Enable a task type",
|
|
|
|
ArgsUsage: "[" + settableStr + "]",
|
2021-03-23 12:42:56 +00:00
|
|
|
Action: taskAction(api.Worker.TaskEnable),
|
2020-11-26 16:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var tasksDisableCmd = &cli.Command{
|
|
|
|
Name: "disable",
|
|
|
|
Usage: "Disable a task type",
|
|
|
|
ArgsUsage: "[" + settableStr + "]",
|
2021-03-23 12:42:56 +00:00
|
|
|
Action: taskAction(api.Worker.TaskDisable),
|
2020-11-26 16:33:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 12:42:56 +00:00
|
|
|
func taskAction(tf func(a api.Worker, ctx context.Context, tt sealtasks.TaskType) error) func(cctx *cli.Context) error {
|
2020-11-26 16:33:22 +00:00
|
|
|
return func(cctx *cli.Context) error {
|
2020-11-30 22:19:16 +00:00
|
|
|
if cctx.NArg() != 1 {
|
2020-11-26 16:33:22 +00:00
|
|
|
return xerrors.Errorf("expected 1 argument")
|
|
|
|
}
|
|
|
|
|
|
|
|
var tt sealtasks.TaskType
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
|
|
|
|
api, closer, err := lcli.GetWorkerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
|
|
|
return tf(api, ctx, tt)
|
|
|
|
}
|
|
|
|
}
|