7490: use loggerutil to log any datamanager errors.
[arvados.git] / services / datamanager / summary / file.go
index 8c37e99ade723a5c51a1f80f6c203dce504100d3..63c8adeb745b05b6f8886751cc135b78b0fd8d87 100644 (file)
@@ -22,16 +22,17 @@ type serializedData struct {
 }
 
 var (
-       writeDataTo  string
+       WriteDataTo  string
        readDataFrom string
 )
 
+// DataFetcher to fetch data from keep servers
 type DataFetcher func(arvLogger *logger.Logger,
        readCollections *collection.ReadCollections,
        keepServerInfo *keep.ReadServers)
 
 func init() {
-       flag.StringVar(&writeDataTo,
+       flag.StringVar(&WriteDataTo,
                "write-data-to",
                "",
                "Write summary of data received to this file. Used for development only.")
@@ -41,7 +42,7 @@ func init() {
                "Avoid network i/o and read summary data from this file instead. Used for development only.")
 }
 
-// Writes data we've read to a file.
+// MaybeWriteData writes data we've read to a file.
 //
 // This is useful for development, so that we don't need to read all
 // our data from the network every time we tweak something.
@@ -50,36 +51,34 @@ func init() {
 // working with stale data.
 func MaybeWriteData(arvLogger *logger.Logger,
        readCollections collection.ReadCollections,
-       keepServerInfo keep.ReadServers) bool {
-       if writeDataTo == "" {
-               return false
-       } else {
-               summaryFile, err := os.Create(writeDataTo)
-               if err != nil {
-                       loggerutil.FatalWithMessage(arvLogger,
-                               fmt.Sprintf("Failed to open %s: %v", writeDataTo, err))
-               }
-               defer summaryFile.Close()
+       keepServerInfo keep.ReadServers) error {
+       if WriteDataTo == "" {
+               return nil
+       }
+       summaryFile, err := os.Create(WriteDataTo)
+       if err != nil {
+               return err
+       }
+       defer summaryFile.Close()
 
-               enc := gob.NewEncoder(summaryFile)
-               data := serializedData{
-                       ReadCollections: readCollections,
-                       KeepServerInfo:  keepServerInfo}
-               err = enc.Encode(data)
-               if err != nil {
-                       loggerutil.FatalWithMessage(arvLogger,
-                               fmt.Sprintf("Failed to write summary data: %v", err))
-               }
-               log.Printf("Wrote summary data to: %s", writeDataTo)
-               return true
+       enc := gob.NewEncoder(summaryFile)
+       data := serializedData{
+               ReadCollections: readCollections,
+               KeepServerInfo:  keepServerInfo}
+       err = enc.Encode(data)
+       if err != nil {
+               return err
        }
+       log.Printf("Wrote summary data to: %s", WriteDataTo)
+       return nil
 }
 
+// ShouldReadData should not be used outside of development
 func ShouldReadData() bool {
        return readDataFrom != ""
 }
 
-// Reads data that we've written to a file.
+// ReadData reads data that we've written to a file.
 //
 // This is useful for development, so that we don't need to read all
 // our data from the network every time we tweak something.