src/server/pkg/workload/workload.go
func (w *worker) advanceCommit(c *client.APIClient) error {
	if len(w.started) >= maxStartedCommits || len(w.finished) == 0 {
		// Randomly select a commit that has been started and finish it
		if len(w.started) == 0 {
			return nil
		}
		i := w.rand.Intn(len(w.started))
		commit := w.started[i]

		// Before we finish a commit, we add a file. This assures that there
		// won't be any empty commits which will later crash jobs
		if _, err := c.PutFile(commit.Repo.Name, commit.ID, w.randString(10), w.reader()); err != nil {
			return err
		}
		if err := c.FinishCommit(commit.Repo.Name, commit.ID); err != nil {
			return err
		}
		// remove commit[i] from 'started' and add it to 'finished'
		w.started = append(w.started[:i], w.started[i+1:]...)
		w.finished = append(w.finished, commit)
	} else {
		// Start a new commmit (parented off of a commit that we've finished)
		commit := w.finished[w.rand.Intn(len(w.finished))]
		commit, err := c.StartCommitParent(commit.Repo.Name, "", commit.ID)
		if err != nil {
			return err
		}
		w.started = append(w.started, commit)
	}
	return nil
}
func (w *worker) advanceCommit(c *client.APIClient) error {
	if len(w.started) >= maxStartedCommits || len(w.finished) == 0 {
		// Randomly select a commit that has been started and finish it
		if len(w.started) == 0 {
			return nil
		}
		i := w.rand.Intn(len(w.started))
		commit := w.started[i]

		// Before we finish a commit, we add a file. This assures that there
		// won't be any empty commits which will later crash jobs
		if _, err := c.PutFile(commit.Repo.Name, commit.ID, w.randString(10), w.reader()); err != nil {
			return err
		}
		if err := c.FinishCommit(commit.Repo.Name, commit.ID); err != nil {
			return err
		}
		// remove commit[i] from 'started' and add it to 'finished'
		w.started = append(w.started[:i], w.started[i+1:]...)
		w.finished = append(w.finished, commit)
	} else {
		// Start a new commmit (parented off of a commit that we've finished)
		commit := w.finished[w.rand.Intn(len(w.finished))]
		commit, err := c.StartCommitParent(commit.Repo.Name, "", commit.ID)
		if err != nil {
			return err
		}
		w.started = append(w.started, commit)
	}
	return nil
}
func ( w * worker ) advanceCommit ( c * client . APIClient ) error { if len ( w . started ) >= maxStartedCommits || len ( w . finished ) == 0 { // Randomly select a commit that has been started and finish it if len ( w . started ) == 0 { return nil } i := w . rand . Intn ( len ( w . started ) ) commit := w . started [ i ] // Before we finish a commit, we add a file. This assures that there // won't be any empty commits which will later crash jobs if _ , err := c . PutFile ( commit . Repo . Name , commit . ID , w . randString ( 10 ) , w . reader ( ) ) ; err != nil { return err } if err := c . FinishCommit ( commit . Repo . Name , commit . ID ) ; err != nil { return err } // remove commit[i] from 'started' and add it to 'finished' w . started = append ( w . started [ : i ] , w . started [ i + 1 : ] ... ) w . finished = append ( w . finished , commit ) } else { // Start a new commmit (parented off of a commit that we've finished) commit := w . finished [ w . rand . Intn ( len ( w . finished ) ) ] commit , err := c . StartCommitParent ( commit . Repo . Name , " " , commit . ID ) if err != nil { return err } w . started = append ( w . started , commit ) } return nil }
// advanceCommit either starts or finishes a commit, depending on the state of
// the cluster.
advanceCommit either starts or finishes a commit depending on the state of the cluster .