Beispiel #1
0
func updateDeploymentState(db *sql.DB, d *models.Deployment, state models.DeploymentState) error {
	_, err := db.Exec(deploymentUpdateStateStmt, string(state), d.Id)
	if err != nil {
		return err
	}

	d.State = state
	return nil
}
Beispiel #2
0
func createDeployment(db *sql.DB, d *models.Deployment) error {
	var id int64
	var state models.DeploymentState = models.DEPLOYMENT_NEW
	var createdAt time.Time = time.Now()

	tx, err := db.Begin()
	if err != nil {
		return err
	}
	exists, err := activeDeploymentExists(tx, d.TargetName)
	if err != nil {
		tx.Rollback()
		return err
	}
	if exists {
		tx.Rollback()
		return ErrDeployInProgress
	}

	result, err := tx.Exec(deploymentInsertStmt, d.UserId, d.ApplicationName,
		d.TargetName, d.CommitSha, d.Branch, d.Comment, string(state), createdAt)
	if err != nil {
		tx.Rollback()
		return err
	}

	id, err = result.LastInsertId()
	if err != nil {
		tx.Rollback()
		return err
	}

	d.Id = int(id)
	d.State = state
	d.CreatedAt = createdAt

	tx.Commit()

	return nil
}