Skip to content

Commit

Permalink
Merge pull request #10 from pelican-dev/push_notifications
Browse files Browse the repository at this point in the history
Refactoring of PushServerStateChange
  • Loading branch information
iamkubi authored Apr 20, 2024
2 parents 0f6cd30 + 181b405 commit aa9795b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion remote/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +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
PushServerStateChange(ctx context.Context, sid string, stateChange ServerStateChange) error
}

type client struct {
Expand Down
4 changes: 2 additions & 2 deletions remote/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ func (c *client) getServersPaged(ctx context.Context, page, limit int) ([]RawSer
}

// 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})
func (c *client) PushServerStateChange(ctx context.Context, sid string, sc ServerStateChange) error {
resp, err := c.Post(ctx, fmt.Sprintf("/api/remote/servers/%s/container/status", sid), d{"data": sc})
if err != nil {
return errors.WithStackIf(err)
}
Expand Down
5 changes: 2 additions & 3 deletions remote/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ type InstallStatusRequest struct {
}

type ServerStateChange struct {
PrevState string `json:"previous_state"`
NewState string `json:"new_state"`
ServerUuid string `json:"server_uuid"`
PrevState string `json:"previous_state"`
NewState string `json:"new_state"`
}
5 changes: 3 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ func (s *Server) OnStateChange() {
}

// Push status update to Panel
s.Log().Debug("pushing server status change to panel")
go s.client.PushServerStateChange(s.Context(), remote.ServerStateChange{prevState, st, s.ID()})
sc := remote.ServerStateChange{prevState, st}
s.Log().WithField("state_change", sc).Debug("pushing server status change to panel")
s.client.PushServerStateChange(context.Background(), s.ID(), sc)

// Reset the resource usage to 0 when the process fully stops so that all the UI
// views in the Panel correctly display 0.
Expand Down

0 comments on commit aa9795b

Please sign in to comment.