Skip to content

Commit

Permalink
Add retries to SQL user insert and update operations. (#4860)
Browse files Browse the repository at this point in the history
  • Loading branch information
spew authored and danawillow committed Nov 22, 2019
1 parent 91600a2 commit 606775d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions google/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
retryFunc := func() error {
op, err = config.clientSqlAdmin.Users.Update(project, instance, name,
user).Host(host).Do()
return err
}
err = retryTimeDuration(retryFunc, d.Timeout(schema.TimeoutUpdate))

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

0 comments on commit 606775d

Please sign in to comment.