Skip to content

Commit

Permalink
Add retries to SQL user insert and update operations.
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
danawillow authored and modular-magician committed Nov 22, 2019
1 parent 9764003 commit 58d54a2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions google-beta/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ func resourceSqlUserCreate(d *schema.ResourceData, meta interface{}) error {

mutexKV.Lock(instanceMutexKey(project, instance))
defer mutexKV.Unlock(instanceMutexKey(project, instance))
op, err := config.clientSqlAdmin.Users.Insert(project, instance,
user).Do()
var op *sqladmin.Operation
insertFunc := func() error {
op, err = config.clientSqlAdmin.Users.Insert(project, instance,
user).Do()
return err
}
err = retryTimeDuration(insertFunc, d.Timeout(schema.TimeoutCreate))

if err != nil {
return fmt.Errorf("Error, failed to insert "+
Expand Down Expand Up @@ -172,8 +177,13 @@ func resourceSqlUserUpdate(d *schema.ResourceData, meta interface{}) error {

mutexKV.Lock(instanceMutexKey(project, instance))
defer mutexKV.Unlock(instanceMutexKey(project, instance))
op, err := config.clientSqlAdmin.Users.Update(project, instance, name,
user).Host(host).Do()
var op *sqladmin.Operation
updateFunc := func() error {
op, err = config.clientSqlAdmin.Users.Update(project, instance, name,
user).Host(host).Do()
return err
}
err = retryTimeDuration(updateFunc, d.Timeout(schema.TimeoutUpdate))

if err != nil {
return fmt.Errorf("Error, failed to update"+
Expand Down

0 comments on commit 58d54a2

Please sign in to comment.