Skip to content

Commit 2e843f4

Browse files
author
Antoine Verin
committed
update retry logic to retry all instead of the failing one in postgresql_script resource
1 parent 255d84e commit 2e843f4

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

postgresql/resource_postgresql_script.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package postgresql
33
import (
44
"crypto/sha1"
55
"encoding/hex"
6+
"log"
67
"time"
78

89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -81,20 +82,28 @@ func resourcePostgreSQLScriptDelete(db *DBConnection, d *schema.ResourceData) er
8182
}
8283

8384
func executeCommands(db *DBConnection, commands []any, tries int, timeout int) error {
84-
for _, command := range commands {
85-
for i := 1; ; i++ {
86-
_, err := db.Query(command.(string))
85+
for i := 1; ; i++ {
86+
var err error
87+
for _, command := range commands {
88+
log.Printf("[DEBUG] Executing (%d try) %s", i, command.(string))
89+
_, err = db.Query(command.(string))
90+
8791
if err != nil {
92+
log.Println("[DEBUG] Error catched:", err)
93+
if _, err := db.Query("ROLLBACK"); err != nil {
94+
log.Println("[DEBUG] Rollback raised an error:", err)
95+
}
8896
if i >= tries {
8997
return err
9098
}
9199
time.Sleep(time.Duration(timeout) * time.Second)
92-
continue
100+
break
93101
}
94-
break
102+
}
103+
if err == nil {
104+
return nil
95105
}
96106
}
97-
return nil
98107
}
99108

100109
func shasumCommands(commands []any) string {

0 commit comments

Comments
 (0)