13933: Fix formatting.
[arvados.git] / services / crunch-dispatch-slurm / crunch-dispatch-slurm.go
index 8c5b220b4f0df6bb87a1650516a2fba0e7f591e1..c1009a5d8ed007810a517842d79067811abf03cf 100644 (file)
@@ -57,6 +57,9 @@ type Dispatcher struct {
 
        // Minimum time between two attempts to run the same container
        MinRetryPeriod arvados.Duration
+
+       // Batch size for container queries
+       BatchSize int64
 }
 
 func main() {
@@ -164,6 +167,7 @@ func (disp *Dispatcher) setup() {
        }
        disp.Dispatcher = &dispatch.Dispatcher{
                Arv:            arv,
+               BatchSize:      disp.BatchSize,
                RunContainer:   disp.runContainer,
                PollPeriod:     time.Duration(disp.PollPeriod),
                MinRetryPeriod: time.Duration(disp.MinRetryPeriod),
@@ -277,15 +281,17 @@ func (disp *Dispatcher) runContainer(_ *dispatch.Dispatcher, ctr arvados.Contain
                        var text string
                        if err, ok := err.(dispatchcloud.ConstraintsNotSatisfiableError); ok {
                                var logBuf bytes.Buffer
-                               logBuf.WriteString(fmt.Sprintf("cannot run container %s: %s\n", ctr.UUID, err))
-                               if len(err.AvailableTypes) > 0 {
-                                       logBuf.WriteString("Available instance types:\n")
-                               }
-                               for _, t := range err.AvailableTypes {
-                                       logBuf.WriteString(fmt.Sprintf(
-                                               "Type %q: %d VCPUs, %d RAM, %d Scratch, %f Price\n",
-                                               t.Name, t.VCPUs, t.RAM, t.Scratch, t.Price,
-                                       ))
+                               fmt.Fprintf(&logBuf, "cannot run container %s: %s\n", ctr.UUID, err)
+                               if len(err.AvailableTypes) == 0 {
+                                       fmt.Fprint(&logBuf, "No instance types are configured.\n")
+                               } else {
+                                       fmt.Fprint(&logBuf, "Available instance types:\n")
+                                       for _, t := range err.AvailableTypes {
+                                               fmt.Fprintf(&logBuf,
+                                                       "Type %q: %d VCPUs, %d RAM, %d Scratch, %f Price\n",
+                                                       t.Name, t.VCPUs, t.RAM, t.Scratch, t.Price,
+                                               )
+                                       }
                                }
                                text = logBuf.String()
                                disp.UpdateState(ctr.UUID, dispatch.Cancelled)