Skip to content

Commit

Permalink
Merge pull request #971 from SiaFoundation/chris/merge-dismiss-routes
Browse files Browse the repository at this point in the history
Merge alert dismiss routes
  • Loading branch information
ChrisSchinnerl authored Feb 16, 2024
2 parents 025df16 + f0ea509 commit cd72207
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
18 changes: 10 additions & 8 deletions bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,9 @@ func (b *bus) Handler() http.Handler {
"POST /account/:id/requiressync": b.accountsRequiresSyncHandlerPOST,
"POST /account/:id/resetdrift": b.accountsResetDriftHandlerPOST,

"GET /alerts": b.handleGETAlerts,
"POST /alerts/dismiss": b.handlePOSTAlertsDismiss,
"POST /alerts/dismissall": b.handlePOSTAlertsDismissAll,
"POST /alerts/register": b.handlePOSTAlertsRegister,
"GET /alerts": b.handleGETAlerts,
"POST /alerts/dismiss": b.handlePOSTAlertsDismiss,
"POST /alerts/register": b.handlePOSTAlertsRegister,

"GET /autopilots": b.autopilotsListHandlerGET,
"GET /autopilot/:id": b.autopilotsHandlerGET,
Expand Down Expand Up @@ -1730,17 +1729,20 @@ func (b *bus) handleGETAlerts(jc jape.Context) {
}

func (b *bus) handlePOSTAlertsDismiss(jc jape.Context) {
var all bool
if jc.DecodeForm("all", &all) != nil {
return
} else if all {
jc.Check("failed to dismiss all alerts", b.alertMgr.DismissAllAlerts(jc.Request.Context()))
return
}
var ids []types.Hash256
if jc.Decode(&ids) != nil {
return
}
jc.Check("failed to dismiss alerts", b.alertMgr.DismissAlerts(jc.Request.Context(), ids...))
}

func (b *bus) handlePOSTAlertsDismissAll(jc jape.Context) {
jc.Check("failed to dismiss alerts", b.alertMgr.DismissAllAlerts(jc.Request.Context()))
}

func (b *bus) handlePOSTAlertsRegister(jc jape.Context) {
var alert alerts.Alert
if jc.Decode(&alert) != nil {
Expand Down
18 changes: 13 additions & 5 deletions bus/client/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@ func (c *Client) Alerts(opts alerts.AlertsOpts) (alerts []alerts.Alert, err erro
return
}

// DismissAllAlerts dimisses all alerts.
// DismissAlerts dimisses the alerts with the given IDs.
func (c *Client) DismissAlerts(ctx context.Context, ids ...types.Hash256) error {
return c.dismissAlerts(ctx, false, ids...)
}

// DismissAllAlerts dimisses all registered alerts.
func (c *Client) DismissAllAlerts(ctx context.Context) error {
return c.c.WithContext(ctx).POST("/alerts/dismissall", nil, nil)
return c.dismissAlerts(ctx, true)
}

// DismissAlerts dimisses the alerts with the given IDs.
func (c *Client) DismissAlerts(ctx context.Context, ids ...types.Hash256) error {
return c.c.WithContext(ctx).POST("/alerts/dismiss", ids, nil)
func (c *Client) dismissAlerts(ctx context.Context, all bool, ids ...types.Hash256) error {
values := url.Values{}
if all {
values.Set("all", fmt.Sprint(true))
}
return c.c.WithContext(ctx).POST("/alerts/dismiss?"+values.Encode(), ids, nil)
}

// RegisterAlert registers the given alert.
Expand Down
2 changes: 1 addition & 1 deletion worker/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestDownloaderStopped(t *testing.T) {

req := sectorDownloadReq{
resps: &sectorResponses{
c: make(chan struct{}),
c: make(chan struct{}, 1),
},
}
dl.enqueue(&req)
Expand Down

0 comments on commit cd72207

Please sign in to comment.