2
0
mirror of https://github.com/carlostrub/sisyphus synced 2024-11-11 19:10:34 +00:00

re-enable watcher

This commit is contained in:
Carlo Strub 2017-05-23 21:30:24 +00:00
parent 1840dff22a
commit 8ce5e2dada
2 changed files with 49 additions and 53 deletions

View File

@ -79,7 +79,7 @@ func CloseDatabases(databases map[Maildir]*bolt.DB) {
if err != nil { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"db": string(key) + "/sisyphus.db", "db": string(key) + "/sisyphus.db",
}).Warn("Unable to close database") }).Error("Unable to close database")
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"db": string(key) + "/sisyphus.db", "db": string(key) + "/sisyphus.db",

View File

@ -4,8 +4,10 @@ import (
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
"strings"
"syscall" "syscall"
"github.com/fsnotify/fsnotify"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/carlostrub/sisyphus" "github.com/carlostrub/sisyphus"
@ -151,58 +153,52 @@ func main() {
} }
} }
// // Classify on arrival // Classify whenever a mail arrives in "new"
// watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
// if err != nil { if err != nil {
//log.WithFields(log.Fields{ log.WithFields(log.Fields{
// "err": err, "err": err,
//}).Warning("Cannot create directory watcher") }).Fatal("Cannot setup directory watcher")
// } }
// defer watcher.Close() defer watcher.Close()
//
// done := make(chan bool) done := make(chan bool)
// go func() { go func() {
// for { for {
// select { select {
// case event := <-watcher.Events: case event := <-watcher.Events:
// if event.Op&fsnotify.Create == fsnotify.Create { if event.Op&fsnotify.Create == fsnotify.Create {
// mailName := strings.Split(event.Name, "/") mailName := strings.Split(event.Name, "/")
// m := sisyphus.Mail{ mailDir := strings.TrimRight(event.Name, "/new/"+mailName[len(mailName)-1])
// Key: mailName[len(mailName)-1], m := sisyphus.Mail{
// } Key: mailName[len(mailName)-1],
// }
// if mailName[len(mailName)-2] == "new" {
// err = m.Classify(db) err = m.Classify(dbs[sisyphus.Maildir(mailDir)])
// if err != nil { if err != nil {
// log.Print(err) log.Print(err)
// } }
// } else {
// err = m.Learn(db) }
// if err != nil { case err := <-watcher.Errors:
// log.Print(err) log.WithFields(log.Fields{
// } "err": err,
// } }).Warning("Problem with directory watcher")
// }
// } }
// case err := <-watcher.Errors: }()
// log.Println("error:", err)
// } for _, val := range maildirPaths {
// } err = watcher.Add(val + "/new")
// }() if err != nil {
// log.WithFields(log.Fields{
// err = watcher.Add(maildirPaths[0] + "/cur") "err": err,
// if err != nil { "dir": val + "/new",
// log.Fatal(err) }).Error("Cannot watch directory")
// } }
// err = watcher.Add(maildirPaths[0] + "/new") }
// if err != nil {
// log.Fatal(err) <-done
// }
// err = watcher.Add(maildirPaths[0] + "/.Junk/cur")
// if err != nil {
// log.Fatal(err)
// }
// <-done
}, },
}, },
{ {