func (b *MemoryBackend) continuousCleanup() { id, shutdownRequested := shutdown.AddShutdownListener("MemoryBackend cleanup") defer shutdown.RoutineDone(id) for { select { case <-time.After(config.GetEmailTTL() / 4): b.doCleanup() case <-shutdownRequested: log.Info("Shutting down memory cleanup with system") return case <-b.quit: log.Info("Quitting memory cleanup") return } } }
func (b *MemoryBackend) PutEmail(e *email.SMTPEmail) (id email.EmailId, err error) { if e == nil { return "", errors.New("Cannot put nil email") } id = email.EmailId(uuid.NewV4().String()) tsEm := timestampedEmail{id, time.Now().Add(config.GetEmailTTL())} // critical section b.rwlock.Lock() b.email_by_id[id] = e b.expiry_queue = append(b.expiry_queue, tsEm) b.rwlock.Unlock() log.WithFields(log.Fields{ "id": id, }).Info("Stored email in memory") return }