<commit_before>package scheduler

import (
	"strings"
	"sync"

	"github.com/NetSys/di/db"
	"github.com/NetSys/di/minion/docker"
)

type swarm struct {
	dk docker.Client
}

func newSwarm(dk docker.Client) scheduler {
	return swarm{dk}
}

func (s swarm) list() ([]docker.Container, error) {
	return s.dk.List(map[string][]string{"label": {"DI=Scheduler"}})
}

func (s swarm) boot(dbcs []db.Container) {
	var wg sync.WaitGroup
	wg.Add(len(dbcs))
	defer wg.Wait()

	for _, dbc := range dbcs {
		dbc := dbc
		go func() {
			log.Info("Starting container: %s %s", dbc.Image,
				strings.Join(dbc.Command, " "))
			err := s.dk.Run(docker.RunOptions{
				Image:  dbc.Image,
				Args:   dbc.Command,
				Labels: map[string]string{"DI": "Scheduler"},
			})
			if err != nil {
				log.Warning("Failed to start container %s: %s",
					dbc.Image, err)
			}
			wg.Done()
		}()
	}
}

func (s swarm) terminate(ids []string) {
	var wg sync.WaitGroup
	wg.Add(len(ids))
	defer wg.Wait()
	for _, id := range ids {
		id := id
		go func() {
			err := s.dk.RemoveID(id)
			if err != nil {
				log.Warning("Failed to stop container: %s", err)
			}
			wg.Done()
		}()
	}
}<commit_msg>swarm: Only log once per failed container boot<commit_after>package scheduler

import (
	"fmt"
	"strings"
	"sync"

	"github.com/NetSys/di/db"
	"github.com/NetSys/di/minion/docker"
)

type swarm struct {
	dk docker.Client
}

func newSwarm(dk docker.Client) scheduler {
	return swarm{dk}
}

func (s swarm) list() ([]docker.Container, error) {
	return s.dk.List(map[string][]string{"label": {"DI=Scheduler"}})
}

func (s swarm) boot(dbcs []db.Container) {
	var wg sync.WaitGroup
	wg.Add(len(dbcs))

	logChn := make(chan string, 1)
	for _, dbc := range dbcs {
		dbc := dbc
		go func() {
			err := s.dk.Run(docker.RunOptions{
				Image:  dbc.Image,
				Args:   dbc.Command,
				Labels: map[string]string{"DI": "Scheduler"},
			})
			if err != nil {
				msg := fmt.Sprintf("Failed to start container %s: %s",
					dbc.Image, err)
				select {
				case logChn <- msg:
				default:
				}
			} else {
				log.Info("Started container: %s %s", dbc.Image,
					strings.Join(dbc.Command, " "))
			}
			wg.Done()
		}()
	}

	wg.Wait()

	select {
	case msg := <-logChn:
		log.Warning(msg)
	default:
	}
}

func (s swarm) terminate(ids []string) {
	var wg sync.WaitGroup
	wg.Add(len(ids))
	defer wg.Wait()
	for _, id := range ids {
		id := id
		go func() {
			err := s.dk.RemoveID(id)
			if err != nil {
				log.Warning("Failed to stop container: %s", err)
			}
			wg.Done()
		}()
	}
}
{'fraction_non_alphanumeric': 0.17465346534653464, 'fraction_numerical': 0.00039603960396039607, 'mean_word_length': 3.0676328502415457, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7026205', 'n_tokens_mistral': 1155, 'n_tokens_neox': 995, 'n_words': 232}