func()

in ccadb2OneCRL/main.go [430:462]


func (u *Updater) PushToStaging() transaction.Transactor {
	committed := 0
	return transaction.NewTransaction().WithCommit(func() error {
		collection := StagingCollection()
		for _, record := range u.changes {
			err := u.staging.NewRecord(collection, record)
			if err != nil {
				return errors.WithStack(err)
			}
			committed += 1
		}
		return nil
	}).WithRollback(func(_ error) error {
		// Try to delete as many of the entries that we can that
		// WERE successfully inserted. Single error while deleting
		// does not fail out the entire rollback, so it is possible
		// for this rollback to leave orphaned data on staging
		// the service is degraded and only sporadically failing.
		var err error = nil
		collection := StagingCollection()
		for i := 0; i < committed; i++ {
			_, e := u.staging.Delete(collection, u.changes[i])
			if e != nil {
				if err == nil {
					err = e
				} else {
					err = errors.Wrap(err, e.Error())
				}
			}
		}
		return errors.WithStack(err)
	})
}