Configure cron to actually send to endpoint

This commit is contained in:
DaneEveritt
2022-07-09 15:47:24 -04:00
parent 28137c4c14
commit 49f3a61d16
4 changed files with 31 additions and 11 deletions

View File

@@ -30,7 +30,7 @@ type Client interface {
SetInstallationStatus(ctx context.Context, uuid string, successful bool) error
SetTransferStatus(ctx context.Context, uuid string, successful bool) error
ValidateSftpCredentials(ctx context.Context, request SftpAuthRequest) (SftpAuthResponse, error)
SendActivityLogs(ctx context.Context, activity [][]byte) error
SendActivityLogs(ctx context.Context, activity []json.RawMessage) error
}
type client struct {
@@ -134,6 +134,9 @@ func (c *client) request(ctx context.Context, method, path string, body *bytes.B
err := backoff.Retry(func() error {
var b bytes.Buffer
if body != nil {
// We have to create a copy of the body, otherwise attempting this request again will
// send no data if there was initially a body since the "requestOnce" method will read
// the whole buffer, thus leaving it empty at the end.
if _, err := b.Write(body.Bytes()); err != nil {
return backoff.Permanent(errors.Wrap(err, "http: failed to copy body buffer"))
}

View File

@@ -3,6 +3,7 @@ package remote
import (
"context"
"fmt"
"github.com/goccy/go-json"
"strconv"
"sync"
@@ -179,8 +180,8 @@ func (c *client) SendRestorationStatus(ctx context.Context, backup string, succe
}
// SendActivityLogs sends activity logs back to the Panel for processing.
func (c *client) SendActivityLogs(ctx context.Context, activity [][]byte) error {
resp, err := c.Post(ctx, "/activty", d{"data": activity})
func (c *client) SendActivityLogs(ctx context.Context, activity []json.RawMessage) error {
resp, err := c.Post(ctx, "/activity", d{"data": activity})
if err != nil {
return errors.WithStackIf(err)
}