@@ -87,26 +87,33 @@ func UpdateApplicationInstance(ctx context.Context, cfg *config.Config, instance
87
87
func UpdateApplicationUser (ctx context.Context , target * resolved.Instance , gcpProject * resolved.GcpProject , mgr * common_main.Manager ) error {
88
88
mgr .Logger .Info ("updating application user" , "user" , target .AppUsername )
89
89
90
- getCtx , cancel := context . WithTimeout ( ctx , 1 * time .Minute )
91
- defer cancel ( )
92
- for {
93
- mgr . Logger . Info ( "waiting for user to be up to date" , "user" , target . AppUsername )
94
- sqlUser , err := mgr .SqlUserClient .Get (getCtx , target .AppUsername )
90
+ b := retry . NewConstant ( 5 * time .Second )
91
+ b = retry . WithMaxDuration ( 5 * time . Minute , b )
92
+
93
+ err := retry . Do ( ctx , b , func ( ctx context. Context ) error {
94
+ sqlUser , err := mgr .SqlUserClient .Get (ctx , target .AppUsername )
95
95
if err != nil {
96
96
if errors .IsNotFound (err ) {
97
- time . Sleep ( 1 * time . Second )
98
- continue
97
+ mgr . Logger . Warn ( "user not found, retrying" , "user" , target . AppUsername )
98
+ return retry . RetryableError ( err )
99
99
}
100
100
return fmt .Errorf ("failed to get sql user: %w" , err )
101
101
}
102
102
103
103
if sqlUser .Status .Conditions [0 ].Reason != "UpToDate" {
104
- time . Sleep ( 3 * time . Second )
105
- continue
104
+ mgr . Logger . Info ( "user not up to date, retrying" , "user" , target . AppUsername )
105
+ return retry . RetryableError ( fmt . Errorf ( "user not up to date" ))
106
106
}
107
- break
107
+
108
+ return nil
109
+ })
110
+
111
+ if err != nil {
112
+ return err
108
113
}
109
114
115
+ mgr .Logger .Info ("user is up to date, setting database password" , "user" , target .AppUsername )
116
+
110
117
return database .SetDatabasePassword (ctx , target .Name , target .AppUsername , target .AppPassword , gcpProject , mgr )
111
118
}
112
119
0 commit comments