Debug worker

This commit is contained in:
Gregory Wells
2026-03-24 18:38:47 -04:00
parent ffb9600089
commit d4512e9cce
3 changed files with 11 additions and 9 deletions

View File

@@ -21,13 +21,12 @@ type LDAPSearch struct {
LDAPSearch *ldap.SearchResult
}
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServer, error) {
func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) *LDAPServer {
logging.Debugf("Connecting to LDAP server %s", URL)
l, err := ldap.DialURL(URL)
if err != nil {
logging.Fatal("Failed to connect to LDAP server")
logging.Fatal(err.Error())
return nil, err
}
logging.Infof("Connected to LDAP server")
@@ -44,7 +43,7 @@ func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServ
URL: URL,
StartTLS: starttls,
IgnoreInsecureCert: ignore_cert,
}, nil
}
}
func reconnectToLDAPServer(server *LDAPServer) {
@@ -119,7 +118,11 @@ func modifyLDAPAttribute(server *LDAPServer, userDN string, attribute string, da
func closeLDAPServer(server *LDAPServer) {
if server != nil && server.Connection != nil {
server.Connection.Close()
logging.Debug("Closing connection to LDAP server")
err := server.Connection.Close()
if err != nil {
logging.Errorf("Failed to close LDAP server %s", err.Error())
}
}
}

View File

@@ -321,13 +321,9 @@ func main() {
}
ldapServerMutex.Lock()
server, err := connectToLDAPServer(serverConfig.LDAPConfig.LDAPURL, serverConfig.LDAPConfig.Security == "tls", serverConfig.LDAPConfig.IgnoreInvalidCert)
server := connectToLDAPServer(serverConfig.LDAPConfig.LDAPURL, serverConfig.LDAPConfig.Security == "tls", serverConfig.LDAPConfig.IgnoreInvalidCert)
ldapServer = server
ldapServerMutex.Unlock()
if err != nil {
log.Fatal(err)
return
}
defer closeLDAPServer(ldapServer)
createWorker(time.Minute*5, cleanupSessions)

View File

@@ -2,9 +2,12 @@ package main
import (
"time"
"astraltech.xyz/accountmanager/src/logging"
)
func createWorker(interval time.Duration, task func()) {
logging.Debugf("Creating worker that runs on a %s interval", interval.String())
go func() {
ticker := time.NewTicker(interval)
defer ticker.Stop()