Add StoreReport methods to stores

Not sure if we'll use them.
This commit is contained in:
Jonathan Lange
2016-07-15 09:42:45 +01:00
parent 60e14c1dc2
commit 270a55060f
2 changed files with 16 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package multitenant
import (
"bytes"
"compress/gzip"
"fmt"
"net"
"sort"
@@ -202,6 +203,13 @@ func (c *MemcacheClient) FetchReports(keys []string) (map[string]report.Report,
return reports, missing, nil
}
// StoreReport serializes and stores a report.
func (c *MemcacheClient) StoreReport(key string, report *report.Report) error {
var buf bytes.Buffer
report.WriteBinary(&buf, gzip.BestCompression)
return c.StoreBytes(key, buf.Bytes())
}
// StoreBytes stores a report, expecting the report to be serialized already.
func (c *MemcacheClient) StoreBytes(key string, content []byte) error {
return instrument.TimeRequestHistogramStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error {

View File

@@ -2,6 +2,7 @@ package multitenant
import (
"bytes"
"compress/gzip"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
@@ -84,6 +85,13 @@ func (store *S3Store) fetchReport(key string) (*report.Report, error) {
return report.MakeFromBinary(resp.Body)
}
// StoreReport serializes and stores a report.
func (store *S3Store) StoreReport(key string, report *report.Report) error {
var buf bytes.Buffer
report.WriteBinary(&buf, gzip.BestCompression)
return store.StoreBytes(key, buf.Bytes())
}
// StoreBytes stores a report in S3, expecting the report to be serialized
// already.
func (store *S3Store) StoreBytes(key string, content []byte) error {