Skip to content

Commit

Permalink
Merge pull request #8 from pelican-dev/push_notifications
Browse files Browse the repository at this point in the history
Push notification to panel on container state change
  • Loading branch information
iamkubi authored Apr 20, 2024
2 parents 62ef8f0 + 7bf9f6a commit 83d1bd5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions remote/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Client interface {
SetTransferStatus(ctx context.Context, uuid string, successful bool) error
ValidateSftpCredentials(ctx context.Context, request SftpAuthRequest) (SftpAuthResponse, error)
SendActivityLogs(ctx context.Context, activity []models.Activity) error
PushServerStateChange(ctx context.Context, stateChange ServerStateChange) error
}

type client struct {
Expand Down
10 changes: 10 additions & 0 deletions remote/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,13 @@ func (c *client) getServersPaged(ctx context.Context, page, limit int) ([]RawSer
}
return r.Data, r.Meta, nil
}

// PushServerStateChange updates the Panel with state change notifications
func (c *client) PushServerStateChange(ctx context.Context, sc ServerStateChange) error {
resp, err := c.Post(ctx, fmt.Sprintf("/api/remote/servers/%s/container/status", sc.ServerUuid), d{"data": sc})
if err != nil {
return errors.WithStackIf(err)
}
_ = resp.Body.Close()
return nil
}
6 changes: 6 additions & 0 deletions remote/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,9 @@ type InstallStatusRequest struct {
Successful bool `json:"successful"`
Reinstall bool `json:"reinstall"`
}

type ServerStateChange struct {
PrevState string `json:"previous_state"`
NewState string `json:"new_state"`
ServerUuid string `json:"server_uuid"`
}
4 changes: 4 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ func (s *Server) OnStateChange() {
s.Events().Publish(StatusEvent, st)
}

// Push status update to Panel
s.Log().Debug("pushing server status change to panel")
s.client.PushServerStateChange(s.Context(), remote.ServerStateChange{prevState, st, s.ID()})

// Reset the resource usage to 0 when the process fully stops so that all the UI
// views in the Panel correctly display 0.
if st == environment.ProcessOfflineState {
Expand Down

0 comments on commit 83d1bd5

Please sign in to comment.