Skip to content

Commit

Permalink
Merge pull request #931 from ipfs-force-community/feat/0x5459/wdpost-…
Browse files Browse the repository at this point in the history
…show-sectors

Feat/0x5459/wdpost show sectors
  • Loading branch information
LinZexiao authored Sep 1, 2023
2 parents 91e5e3b + 8cd3d49 commit 59111ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
10 changes: 6 additions & 4 deletions damocles-manager/cmd/damocles-manager/internal/util_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ var utilWdPostListCmd = &cli.Command{

w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
if detail {
_, err = w.Write([]byte("JobID\tPrefix\tMiner\tDDL\tPartitions\tWorker\tState\tTry\tCreateAt\tStartedAt\tHeartbeatAt\tFinishedAt\tUpdatedAt\tError\n"))
_, err = w.Write([]byte("JobID\tPrefix\tMiner\tDDL\tPartitions\tSectors\tWorker\tState\tTry\tCreateAt\tStartedAt\tHeartbeatAt\tFinishedAt\tUpdatedAt\tError\n"))
} else {
_, err = w.Write([]byte("JobID\tMinerID\tDDL\tPartitions\tWorker\tState\tTry\tCreateAt\tElapsed\tHeartbeat\tError\n"))
_, err = w.Write([]byte("JobID\tMinerID\tDDL\tPartitions\tSectors\tWorker\tState\tTry\tCreateAt\tElapsed\tHeartbeat\tError\n"))
}
if err != nil {
return err
Expand All @@ -365,12 +365,13 @@ var utilWdPostListCmd = &cli.Command{
continue
}
if detail {
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
job.ID,
job.State,
job.Input.MinerID,
job.DeadlineIdx,
strings.Join(job.Partitions, ","),
job.Sectors,
job.WorkerName,
job.DisplayState(),
job.TryNum,
Expand All @@ -396,11 +397,12 @@ var utilWdPostListCmd = &cli.Command{
heartbeat = "-"
}

fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\n",
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%d\t%s\t%s\t%d\t%s\t%s\t%s\t%s\n",
job.ID,
job.Input.MinerID,
job.DeadlineIdx,
strings.Join(job.Partitions, ","),
job.Sectors,
job.WorkerName,
job.DisplayState(),
job.TryNum,
Expand Down
35 changes: 25 additions & 10 deletions damocles-manager/core/types_wdpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -67,31 +68,45 @@ func (t *WdPoStJob) Succeed() bool {
return t.ErrorReason == ""
}

func (t *WdPoStJob) DisplayState() string {
switch WdPoStJobState(t.State) {
type WdPoStJobBrief struct {
*WdPoStJob
Sectors uint32
Faults uint32
}

func (j *WdPoStJobBrief) DisplayState() string {
switch WdPoStJobState(j.State) {
case WdPoStJobReadyToRun:
return "ReadyToRun"
case WdPoStJobRunning:
return "Running"
case WdPoStJobFinished:
if t.Succeed() {
return "Succeed"
if j.Succeed() {
if j.Faults == 0 {
return "Succeed"
}
return fmt.Sprintf("Faults(%d)", j.Faults)
}
return "Failed"
}
return t.State
}

type WdPoStJobBrief struct {
*WdPoStJob
return j.State
}

func (j *WdPoStJobBrief) MarshalJSON() ([]byte, error) {
j.WdPoStJob.Input = WdPoStInput{
MinerID: j.WdPoStJob.Input.MinerID,
}
j.WdPoStJob.Output = &stage.WindowPoStOutput{}
return json.Marshal(&j.WdPoStJob)

return json.Marshal(struct {
*WdPoStJob
Sectors uint32
Faults uint32
}{
WdPoStJob: j.WdPoStJob,
Sectors: j.Sectors,
Faults: j.Faults,
})
}

type WdPoStAllocatedJob struct {
Expand Down
6 changes: 6 additions & 0 deletions damocles-manager/modules/impl/prover/worker/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ func (api WdPoStAPIImpl) WdPoStAllJobs(ctx context.Context) ([]core.WdPoStJobBri
return nil, err
}
return slices.Map(jobs, func(job *core.WdPoStJob) core.WdPoStJobBrief {
faults := 0
if job.Output != nil {
faults = len(job.Output.Faults)
}
return core.WdPoStJobBrief{
WdPoStJob: job,
Sectors: uint32(len(job.Input.Sectors)),
Faults: uint32(faults),
}
}), nil
}

0 comments on commit 59111ae

Please sign in to comment.