Skip to content

Commit 3f3e83f

Browse files
author
Antoine Verin
committed
rename timeout to backoffDelay
1 parent e1a4937 commit 3f3e83f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

postgresql/resource_postgresql_script.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
)
1111

1212
const (
13-
scriptCommandsAttr = "commands"
14-
scriptTriesAttr = "tries"
15-
scriptTimeoutAttr = "timeout"
16-
scriptShasumAttr = "shasum"
13+
scriptCommandsAttr = "commands"
14+
scriptTriesAttr = "tries"
15+
scriptBackoffDelayAttr = "backoffDelay"
16+
scriptShasumAttr = "shasum"
1717
)
1818

1919
func resourcePostgreSQLScript() *schema.Resource {
@@ -38,7 +38,7 @@ func resourcePostgreSQLScript() *schema.Resource {
3838
Default: 1,
3939
Description: "Number of tries for a failing command",
4040
},
41-
scriptTimeoutAttr: {
41+
scriptBackoffDelayAttr: {
4242
Type: schema.TypeInt,
4343
Optional: true,
4444
Default: 1,
@@ -56,11 +56,11 @@ func resourcePostgreSQLScript() *schema.Resource {
5656
func resourcePostgreSQLScriptCreateOrUpdate(db *DBConnection, d *schema.ResourceData) error {
5757
commands := d.Get(scriptCommandsAttr).([]any)
5858
tries := d.Get(scriptTriesAttr).(int)
59-
timeout := d.Get(scriptTimeoutAttr).(int)
59+
backoffDelay := d.Get(scriptBackoffDelayAttr).(int)
6060

6161
sum := shasumCommands(commands)
6262

63-
if err := executeCommands(db, commands, tries, timeout); err != nil {
63+
if err := executeCommands(db, commands, tries, backoffDelay); err != nil {
6464
return err
6565
}
6666

@@ -81,7 +81,7 @@ func resourcePostgreSQLScriptDelete(db *DBConnection, d *schema.ResourceData) er
8181
return nil
8282
}
8383

84-
func executeCommands(db *DBConnection, commands []any, tries int, timeout int) error {
84+
func executeCommands(db *DBConnection, commands []any, tries int, backoffDelay int) error {
8585
for i := 1; ; i++ {
8686
var err error
8787
for _, command := range commands {
@@ -90,13 +90,13 @@ func executeCommands(db *DBConnection, commands []any, tries int, timeout int) e
9090

9191
if err != nil {
9292
log.Println("[DEBUG] Error catched:", err)
93-
if _, err := db.Query("ROLLBACK"); err != nil {
94-
log.Println("[DEBUG] Rollback raised an error:", err)
93+
if _, rollbackError := db.Query("ROLLBACK"); rollbackError != nil {
94+
log.Println("[DEBUG] Rollback raised an error:", rollbackError)
9595
}
9696
if i >= tries {
9797
return err
9898
}
99-
time.Sleep(time.Duration(timeout) * time.Second)
99+
time.Sleep(time.Duration(backoffDelay) * time.Second)
100100
break
101101
}
102102
}

0 commit comments

Comments
 (0)