-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5023 from filecoin-project/feat/worker-set-task-t…
…ypes worker: Support setting task types at runtime
- Loading branch information
Showing
9 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ func main() { | |
storageCmd, | ||
setCmd, | ||
waitQuietCmd, | ||
tasksCmd, | ||
} | ||
|
||
app := &cli.App{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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{}{ | ||
sealtasks.TTAddPiece: {}, | ||
sealtasks.TTPreCommit1: {}, | ||
sealtasks.TTPreCommit2: {}, | ||
sealtasks.TTCommit2: {}, | ||
sealtasks.TTUnseal: {}, | ||
} | ||
|
||
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 + "]", | ||
Action: taskAction(api.WorkerAPI.TaskEnable), | ||
} | ||
|
||
var tasksDisableCmd = &cli.Command{ | ||
Name: "disable", | ||
Usage: "Disable a task type", | ||
ArgsUsage: "[" + settableStr + "]", | ||
Action: taskAction(api.WorkerAPI.TaskDisable), | ||
} | ||
|
||
func taskAction(tf func(a api.WorkerAPI, 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") | ||
} | ||
|
||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters