ReportPluginStatus marshals the given report, sets NodeID and UpdatedAt, and pushes it to the provided client with a timeout.
(ctx context.Context, client PluginStatusClient, nodeID string, report homeplugins.SyncReport)
| 20 | // ReportPluginStatus marshals the given report, sets NodeID and UpdatedAt, |
| 21 | // and pushes it to the provided client with a timeout. |
| 22 | func ReportPluginStatus(ctx context.Context, client PluginStatusClient, nodeID string, report homeplugins.SyncReport) error { |
| 23 | if client == nil { |
| 24 | return fmt.Errorf("home plugin status client is unavailable") |
| 25 | } |
| 26 | nodeID = strings.TrimSpace(nodeID) |
| 27 | if nodeID == "" { |
| 28 | return fmt.Errorf("home plugin status node id is empty") |
| 29 | } |
| 30 | report.NodeID = nodeID |
| 31 | report.UpdatedAt = time.Now().UTC() |
| 32 | raw, errMarshal := json.Marshal(report) |
| 33 | if errMarshal != nil { |
| 34 | return errMarshal |
| 35 | } |
| 36 | if ctx == nil { |
| 37 | ctx = context.Background() |
| 38 | } |
| 39 | reportCtx, cancel := context.WithTimeout(ctx, pluginStatusReportTimeout) |
| 40 | defer cancel() |
| 41 | return client.RPushPluginStatus(reportCtx, raw) |
| 42 | } |