Skip to content

Commit

Permalink
fix the resume button in sector info UI (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored Jul 31, 2024
1 parent 56c8b2c commit fe6413b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 42 deletions.
45 changes: 5 additions & 40 deletions web/api/webrpc/sector.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,60 +408,25 @@ func (a *WebRPC) SectorInfo(ctx context.Context, sp string, intid int64) (*Secto

Resumable: hasAnyStuckTask,
}, nil

//a.executePageTemplate(w, "sector_info", "Sector Info", mi)
}

func (a *WebRPC) SectorResume(ctx context.Context, sp, id string) error {
intid, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return xerrors.Errorf("invalid id")
}

maddr, err := address.NewFromString(sp)
if err != nil {
return xerrors.Errorf("invalid sp")
}

spid, err := address.IDFromAddress(maddr)
if err != nil {
return xerrors.Errorf("invalid sp")
}

// call CREATE OR REPLACE FUNCTION unset_task_id(sp_id_param bigint, sector_number_param bigint)

_, err = a.deps.DB.Exec(ctx, `SELECT unset_task_id($1, $2)`, spid, intid)
func (a *WebRPC) SectorResume(ctx context.Context, spid, id int) error {
_, err := a.deps.DB.Exec(ctx, `SELECT unset_task_id($1, $2)`, spid, id)
if err != nil {
return xerrors.Errorf("failed to resume sector: %w", err)
}
return nil
}

func (a *WebRPC) SectorRemove(ctx context.Context, sp, id string) error {

intid, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return xerrors.Errorf("invalid id")
}

maddr, err := address.NewFromString(sp)
if err != nil {
return xerrors.Errorf("invalid sp")
}

spid, err := address.IDFromAddress(maddr)
if err != nil {
return xerrors.Errorf("invalid sp")
}

_, err = a.deps.DB.Exec(ctx, `DELETE FROM sectors_sdr_pipeline WHERE sp_id = $1 AND sector_number = $2`, spid, intid)
func (a *WebRPC) SectorRemove(ctx context.Context, spid, id int) error {
_, err := a.deps.DB.Exec(ctx, `DELETE FROM sectors_sdr_pipeline WHERE sp_id = $1 AND sector_number = $2`, spid, id)
if err != nil {
return xerrors.Errorf("failed to resume sector: %w", err)
}

_, err = a.deps.DB.Exec(ctx, `INSERT INTO storage_removal_marks (sp_id, sector_num, sector_filetype, storage_id, created_at, approved, approved_at)
SELECT miner_id, sector_num, sector_filetype, storage_id, current_timestamp, FALSE, NULL FROM sector_location
WHERE miner_id = $1 AND sector_num = $2`, spid, intid)
WHERE miner_id = $1 AND sector_num = $2`, spid, id)
if err != nil {
return xerrors.Errorf("failed to mark sector for removal: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions web/static/pages/sector/sector-info.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ customElements.define('sector-info',class SectorInfo extends LitElement {
<div>
<details>
<summary class="btn btn-warning">Remove ${!this.data.PipelinePoRep?.Failed ? '(THIS SECTOR IS NOT FAILED!)' : ''}</summary>
<button class="btn btn-danger" onclick="${this.removeSector}">Confirm Remove</button>
<button class="btn btn-danger" @click="${() => this.removeSector()}">Confirm Remove</button>
</details>
${this.data.Resumable ? html`<button class="btn btn-primary" onclick="${this.resumeSector}">Resume</button>` : ''}
${this.data.Resumable ? html`<button class="btn btn-primary" @click="${() => this.resumeSector()}">Resume</button>` : ''}
</div>
<div>
<h3>PoRep Pipeline</h3>
Expand Down

0 comments on commit fe6413b

Please sign in to comment.