예제 #1
0
// GetRecentRolls retrieves the most recent N issues from the database.
func (d *db) GetRecentRolls(N int) ([]*autoroll.AutoRollIssue, error) {
	var rv []*autoroll.AutoRollIssue
	if err := d.db.View(func(tx *bolt.Tx) error {
		// Retrieve the issue keys from the by-date bucket.
		byDate := tx.Bucket(BUCKET_ROLLS_BY_DATE)
		c := byDate.Cursor()
		keys := make([][]byte, 0, N)
		for k, v := c.Last(); k != nil && len(keys) < N; k, v = c.Prev() {
			keys = append(keys, v)
		}

		// Retrieve the issues themselves.
		b := tx.Bucket(BUCKET_ROLLS)
		rv = make([]*autoroll.AutoRollIssue, 0, len(keys))
		for _, k := range keys {
			serialized := b.Get(k)
			if serialized == nil {
				return fmt.Errorf("DB consistency error: bucket %s contains data not present in bucket %s!", BUCKET_ROLLS_BY_DATE, BUCKET_ROLLS)
			}
			var a autoroll.AutoRollIssue
			if err := json.Unmarshal(serialized, &a); err != nil {
				return err
			}
			a.Created = a.Created.UTC()
			a.Modified = a.Modified.UTC()
			rv = append(rv, &a)
		}
		return nil
	}); err != nil {
		return nil, err
	}
	return rv, nil
}
예제 #2
0
// closeIssue closes the given issue with the given message.
func (r *AutoRoller) closeIssue(issue *autoroll.AutoRollIssue, result, msg string) error {
	glog.Infof("Closing issue %d (result %q) with message: %s", issue.Issue, result, msg)
	if err := r.rietveld.Close(issue.Issue, msg); err != nil {
		return err
	}
	issue.Result = result
	issue.Closed = true
	issue.CommitQueue = false
	issue.CommitQueueDryRun = false
	return r.recent.Update(issue)
}
예제 #3
0
// Update updates the given DEPS roll in the recent rolls list.
func (r *RecentRolls) Update(roll *autoroll.AutoRollIssue) error {
	if err := roll.Validate(); err != nil {
		return err
	}

	r.mtx.Lock()
	defer r.mtx.Unlock()
	if err := r.db.UpdateRoll(roll); err != nil {
		return err
	}
	return r.refreshRecentRolls()
}
예제 #4
0
// GetRoll retrieves the given issue from the database.
func (d *db) GetRoll(issue int64) (*autoroll.AutoRollIssue, error) {
	var a *autoroll.AutoRollIssue
	if err := d.db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(BUCKET_ROLLS)

		serialized := b.Get(issueToRollKey(issue))
		if serialized == nil {
			return nil
		}
		a = &autoroll.AutoRollIssue{}
		if err := json.Unmarshal(serialized, a); err != nil {
			return err
		}
		a.Created = a.Created.UTC()
		a.Modified = a.Modified.UTC()
		return nil
	}); err != nil {
		return nil, err
	}
	return a, nil
}
예제 #5
0
// Add adds a DEPS roll to the recent rolls list.
func (r *RecentRolls) Add(roll *autoroll.AutoRollIssue) error {
	if err := roll.Validate(); err != nil {
		return err
	}

	r.mtx.Lock()
	defer r.mtx.Unlock()

	// Refuse to insert more rolls if we already have an active roll.
	if r.currentRoll() != nil {
		return fmt.Errorf("There is already an active roll. Cannot add another.")
	}

	// Validate the new roll.
	if roll.Closed {
		return fmt.Errorf("Cannot insert a new roll which is already closed.")
	}

	if err := r.db.InsertRoll(roll); err != nil {
		return err
	}
	return r.refreshRecentRolls()
}