@@ -10,10 +10,10 @@ import (
10
10
)
11
11
12
12
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"
17
17
)
18
18
19
19
func resourcePostgreSQLScript () * schema.Resource {
@@ -38,7 +38,7 @@ func resourcePostgreSQLScript() *schema.Resource {
38
38
Default : 1 ,
39
39
Description : "Number of tries for a failing command" ,
40
40
},
41
- scriptTimeoutAttr : {
41
+ scriptBackoffDelayAttr : {
42
42
Type : schema .TypeInt ,
43
43
Optional : true ,
44
44
Default : 1 ,
@@ -56,11 +56,11 @@ func resourcePostgreSQLScript() *schema.Resource {
56
56
func resourcePostgreSQLScriptCreateOrUpdate (db * DBConnection , d * schema.ResourceData ) error {
57
57
commands := d .Get (scriptCommandsAttr ).([]any )
58
58
tries := d .Get (scriptTriesAttr ).(int )
59
- timeout := d .Get (scriptTimeoutAttr ).(int )
59
+ backoffDelay := d .Get (scriptBackoffDelayAttr ).(int )
60
60
61
61
sum := shasumCommands (commands )
62
62
63
- if err := executeCommands (db , commands , tries , timeout ); err != nil {
63
+ if err := executeCommands (db , commands , tries , backoffDelay ); err != nil {
64
64
return err
65
65
}
66
66
@@ -81,7 +81,7 @@ func resourcePostgreSQLScriptDelete(db *DBConnection, d *schema.ResourceData) er
81
81
return nil
82
82
}
83
83
84
- func executeCommands (db * DBConnection , commands []any , tries int , timeout int ) error {
84
+ func executeCommands (db * DBConnection , commands []any , tries int , backoffDelay int ) error {
85
85
for i := 1 ; ; i ++ {
86
86
var err error
87
87
for _ , command := range commands {
@@ -90,13 +90,13 @@ func executeCommands(db *DBConnection, commands []any, tries int, timeout int) e
90
90
91
91
if err != nil {
92
92
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 )
95
95
}
96
96
if i >= tries {
97
97
return err
98
98
}
99
- time .Sleep (time .Duration (timeout ) * time .Second )
99
+ time .Sleep (time .Duration (backoffDelay ) * time .Second )
100
100
break
101
101
}
102
102
}
0 commit comments