Clean mqueue every 24h of > 24h closed connections

This commit is contained in:
yo 2022-07-26 19:59:26 +02:00
parent 8a4ba4486d
commit b82615a974

View File

@ -125,7 +125,7 @@ var (
File os.File
Writer *bufio.Writer
Version = "0.6.6"
Version = "0.6.7"
BuildInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "openldaplogparser_build_info",
@ -321,35 +321,30 @@ func writeOut(msg string, filename string) error {
return nil
}
// Every 24H, remove sent, milter-rejected and deferred that entered queue more than 5 days ago
/*
func periodicallyCleanMQueue(mqueue map[int]*PostfixLogParser, mqMtx *sync.Mutex) {
var ok int
// Every 24H, remove connections closed more than 24 hours ago
func periodicallyCleanMQueue(mqueue map[int]*OpenLdapConnection, mqMtx *sync.Mutex) {
var ok bool
for range time.Tick(time.Hour * 24) {
// Do we need read lock?
for _, inmail := range mqueue {
ok = 0
// Check all mails were sent (multiple destinations mails)
// or rejected
for _, outmail := range inmail.Messages {
if outmail.Status == "sent" || outmail.Status == "milter-reject" {
ok += 1
} else if outmail.Status == "deferred" {
if inmail.Time.Add(time.Hour * 5 * 24).Before(time.Now()) {
ok += 1
for _, ldcon := range mqueue {
ok = false
// Check if a close operation exist
for _, op := range ldcon.Operations {
if op.OpType == "close" {
if op.Time.Add(time.Hour * 1 * 24).Before(time.Now()) {
ok = true
}
}
}
if ok == len(inmail.Messages) {
if ok == true {
mqMtx.Lock()
delete(mqueue, inmail.MessageId)
delete(mqueue, ldcon.ConnId)
mqMtx.Unlock()
}
}
}
}
*/
func initConfig() {}