]> git.giacomolli.uk - onechat/blobdiff - build_run.go
Exempt tracker metadata from commit signing
[onechat] / build_run.go
index 707a928070cc0452940b4a7dd434120085779277..44d636db9502e2b57bb0fd8951ef35f998346727 100644 (file)
@@ -175,6 +175,60 @@ func buildReadUsage(path string) (records []ModelUsageRecord, err error) {
        return records, nil
 }
 
+// buildStop returns why a build run must stop: a failed call, or a quota window
+// whose used percent grew by more than buildQuotaLimit points since the first
+// call. It returns "" when the run can go on.
+func buildStop(records []ModelUsageRecord) string {
+       for _, record := range records {
+               if record.Error != "" {
+                       return "call failed: " + record.Error
+               }
+       }
+
+       if len(records) == 0 {
+               return ""
+       }
+
+       first := buildUsedPercents(records[0])
+       for name, used := range buildUsedPercents(records[len(records)-1]) {
+               start, found := first[name]
+               if found && used-start > buildQuotaLimit {
+                       return fmt.Sprintf("%s grew from %g to %g", name, start, used)
+               }
+       }
+
+       return ""
+}
+
+// buildCallStart returns the start of the call of record, or the zero time when
+// its date is not valid.
+func buildCallStart(record ModelUsageRecord) time.Time {
+       start, err := time.Parse(time.RFC3339Nano, record.Date)
+       if err != nil {
+               return time.Time{}
+       }
+
+       return start
+}
+
+// buildUsedPercents returns the used percent of each quota window of record, by
+// header name.
+func buildUsedPercents(record ModelUsageRecord) map[string]float64 {
+       used := make(map[string]float64)
+       for name, value := range record.Quota {
+               if !strings.HasSuffix(name, "-used-percent") {
+                       continue
+               }
+
+               percent, err := strconv.ParseFloat(value, 64)
+               if err == nil {
+                       used[name] = percent
+               }
+       }
+
+       return used
+}
+
 // buildWriteReport writes the result of a build run.
 func buildWriteReport(out io.Writer, appended int, stop string, records []ModelUsageRecord, sizes []int) error {
        var input, cached, output, failed int
@@ -224,42 +278,6 @@ func buildWriteReport(out io.Writer, appended int, stop string, records []ModelU
        return nil
 }
 
-// buildStop returns why a build run must stop: a failed call, or a quota window
-// whose used percent grew by more than buildQuotaLimit points since the first
-// call. It returns "" when the run can go on.
-func buildStop(records []ModelUsageRecord) string {
-       for _, record := range records {
-               if record.Error != "" {
-                       return "call failed: " + record.Error
-               }
-       }
-
-       if len(records) == 0 {
-               return ""
-       }
-
-       first := buildUsedPercents(records[0])
-       for name, used := range buildUsedPercents(records[len(records)-1]) {
-               start, found := first[name]
-               if found && used-start > buildQuotaLimit {
-                       return fmt.Sprintf("%s grew from %g to %g", name, start, used)
-               }
-       }
-
-       return ""
-}
-
-// buildCallStart returns the start of the call of record, or the zero time when
-// its date is not valid.
-func buildCallStart(record ModelUsageRecord) time.Time {
-       start, err := time.Parse(time.RFC3339Nano, record.Date)
-       if err != nil {
-               return time.Time{}
-       }
-
-       return start
-}
-
 // buildRatio returns a / b, or 0 when b is 0.
 func buildRatio(a, b int) float64 {
        if b == 0 {
@@ -345,21 +363,3 @@ func buildQuotaText(record ModelUsageRecord) string {
 
        return strings.Join(parts, " ")
 }
-
-// buildUsedPercents returns the used percent of each quota window of record, by
-// header name.
-func buildUsedPercents(record ModelUsageRecord) map[string]float64 {
-       used := make(map[string]float64)
-       for name, value := range record.Quota {
-               if !strings.HasSuffix(name, "-used-percent") {
-                       continue
-               }
-
-               percent, err := strconv.ParseFloat(value, 64)
-               if err == nil {
-                       used[name] = percent
-               }
-       }
-
-       return used
-}