Skip to content

Commit

Permalink
chore: log errors of ssl generate task (#1110) (#1111)
Browse files Browse the repository at this point in the history
* chore: log errors of ssl generate task

* chore: log errors of ssl generate task

(cherry picked from commit 39eea4f)

Co-authored-by: Tanmoy Sarkar <[email protected]>
  • Loading branch information
mergify[bot] and tanmoysrt authored Dec 1, 2024
1 parent db6f07a commit 3099231
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions swiftwave_service/worker/process_ssl_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

haproxymanager "github.com/swiftwave-org/swiftwave/haproxy_manager"
"github.com/swiftwave-org/swiftwave/swiftwave_service/core"
"github.com/swiftwave-org/swiftwave/swiftwave_service/logger"
"github.com/swiftwave-org/swiftwave/swiftwave_service/manager"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -40,6 +41,7 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
return nil
}
_ = domain.UpdateSSLStatus(ctx, dbWithoutTx, core.DomainSSLStatusFailed)
logger.CronJobLoggerError.Println("Domain", domain.Name, "is not pointing to this server. Marking SSL Issue as failed")
return nil
}
// generate private key [if not found]
Expand All @@ -51,6 +53,7 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
domain.SSLPrivateKey = privateKey
err = domain.Update(ctx, dbWithoutTx)
if err != nil {
logger.CronJobLoggerError.Println("Failed to update domain", domain.Name, "with private key.", err.Error(), "\nWill retry later")
return err
}
}
Expand All @@ -74,11 +77,13 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
// fetch all proxy servers
proxyServers, err := core.FetchProxyActiveServers(&m.ServiceManager.DbClient)
if err != nil {
logger.CronJobLoggerError.Println("Failed to fetch proxy servers while generating SSL certificate", err.Error(), "\nWill retry later")
return err
}
// fetch all haproxy managers
haproxyManagers, err := manager.HAProxyClients(context.Background(), proxyServers)
if err != nil {
logger.CronJobLoggerError.Println("Failed to fetch haproxy managers while generating SSL certificate", err.Error())
return err
}
// map of server ip and transaction id
Expand All @@ -89,13 +94,15 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
// generate a new transaction id for haproxy
transactionId, err := haproxyManager.FetchNewTransactionId()
if err != nil {
logger.CronJobLoggerError.Println("Failed to fetch new transaction id while generating SSL certificate", err.Error(), "\nWill retry later")
return err
}
// add to map
transactionIdMap[haproxyManager] = transactionId
// upload certificate to haproxy
err = haproxyManager.UpdateSSL(transactionId, domain.Name, []byte(domain.SSLPrivateKey), []byte(domain.SSLFullChain))
if err != nil {
logger.CronJobLoggerError.Println("Failed to update SSL certificate while generating SSL certificate", err.Error(), "\nWill retry later")
isFailed = true
break
}
Expand All @@ -107,10 +114,10 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
}
if isFailed || err != nil {
isFailed = true
log.Println("failed to commit haproxy transaction", err)
logger.CronJobLoggerError.Println("Failed to commit haproxy transaction while generating SSL certificate", err.Error())
err := haproxyManager.DeleteTransaction(haproxyTransactionId)
if err != nil {
log.Println("failed to rollback haproxy transaction", err)
logger.CronJobLoggerError.Println("Failed to rollback haproxy transaction while generating SSL certificate", err.Error())
}
}
}
Expand Down

0 comments on commit 3099231

Please sign in to comment.