Skip to content

Commit 39eea4f

Browse files
authored
chore: log errors of ssl generate task (#1110)
* chore: log errors of ssl generate task * chore: log errors of ssl generate task
1 parent 164db55 commit 39eea4f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

swiftwave_service/worker/process_ssl_request.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
haproxymanager "github.com/swiftwave-org/swiftwave/haproxy_manager"
1414
"github.com/swiftwave-org/swiftwave/swiftwave_service/core"
15+
"github.com/swiftwave-org/swiftwave/swiftwave_service/logger"
1516
"github.com/swiftwave-org/swiftwave/swiftwave_service/manager"
1617
"gorm.io/gorm"
1718
)
@@ -40,6 +41,7 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
4041
return nil
4142
}
4243
_ = domain.UpdateSSLStatus(ctx, dbWithoutTx, core.DomainSSLStatusFailed)
44+
logger.CronJobLoggerError.Println("Domain", domain.Name, "is not pointing to this server. Marking SSL Issue as failed")
4345
return nil
4446
}
4547
// generate private key [if not found]
@@ -51,6 +53,7 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
5153
domain.SSLPrivateKey = privateKey
5254
err = domain.Update(ctx, dbWithoutTx)
5355
if err != nil {
56+
logger.CronJobLoggerError.Println("Failed to update domain", domain.Name, "with private key.", err.Error(), "\nWill retry later")
5457
return err
5558
}
5659
}
@@ -74,11 +77,13 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
7477
// fetch all proxy servers
7578
proxyServers, err := core.FetchProxyActiveServers(&m.ServiceManager.DbClient)
7679
if err != nil {
80+
logger.CronJobLoggerError.Println("Failed to fetch proxy servers while generating SSL certificate", err.Error(), "\nWill retry later")
7781
return err
7882
}
7983
// fetch all haproxy managers
8084
haproxyManagers, err := manager.HAProxyClients(context.Background(), proxyServers)
8185
if err != nil {
86+
logger.CronJobLoggerError.Println("Failed to fetch haproxy managers while generating SSL certificate", err.Error())
8287
return err
8388
}
8489
// map of server ip and transaction id
@@ -89,13 +94,15 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
8994
// generate a new transaction id for haproxy
9095
transactionId, err := haproxyManager.FetchNewTransactionId()
9196
if err != nil {
97+
logger.CronJobLoggerError.Println("Failed to fetch new transaction id while generating SSL certificate", err.Error(), "\nWill retry later")
9298
return err
9399
}
94100
// add to map
95101
transactionIdMap[haproxyManager] = transactionId
96102
// upload certificate to haproxy
97103
err = haproxyManager.UpdateSSL(transactionId, domain.Name, []byte(domain.SSLPrivateKey), []byte(domain.SSLFullChain))
98104
if err != nil {
105+
logger.CronJobLoggerError.Println("Failed to update SSL certificate while generating SSL certificate", err.Error(), "\nWill retry later")
99106
isFailed = true
100107
break
101108
}
@@ -107,10 +114,10 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
107114
}
108115
if isFailed || err != nil {
109116
isFailed = true
110-
log.Println("failed to commit haproxy transaction", err)
117+
logger.CronJobLoggerError.Println("Failed to commit haproxy transaction while generating SSL certificate", err.Error())
111118
err := haproxyManager.DeleteTransaction(haproxyTransactionId)
112119
if err != nil {
113-
log.Println("failed to rollback haproxy transaction", err)
120+
logger.CronJobLoggerError.Println("Failed to rollback haproxy transaction while generating SSL certificate", err.Error())
114121
}
115122
}
116123
}

0 commit comments

Comments
 (0)