diff options
author | Adam Mathes <adam@trenchant.org> | 2018-07-06 20:53:17 -0700 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2018-07-06 20:53:17 -0700 |
commit | cdc1f64031af949874fed73e1d51247dd4226660 (patch) | |
tree | 68d4ff3a06d28518ef648e7740e674e158a87029 | |
parent | c8bf5665f43d54dd61f90629d101b954dafe3c89 (diff) | |
download | neko-cdc1f64031af949874fed73e1d51247dd4226660.tar.gz neko-cdc1f64031af949874fed73e1d51247dd4226660.tar.bz2 neko-cdc1f64031af949874fed73e1d51247dd4226660.zip |
try background crawler again
-rw-r--r-- | main.go | 47 |
1 files changed, 23 insertions, 24 deletions
@@ -10,6 +10,7 @@ import ( "adammathes.com/neko/web" "fmt" flag "github.com/ogier/pflag" + "time" ) var Version, Build string @@ -17,7 +18,7 @@ var Version, Build string func main() { var help, update, verbose, proxyImages bool var dbfile, newFeed, export, password string - var port int + var port, minutes int // commands // no command tries to run the web server flag.BoolVarP(&help, "help", "h", false, "print usage information") @@ -28,7 +29,7 @@ func main() { // options with sensible defaults flag.StringVarP(&dbfile, "database", "d", "neko.db", "sqlite database file") flag.IntVarP(&port, "http", "s", 4994, "HTTP port to serve on") - // flag.IntVarP(&minutes, "minutes", "m", 60, "minutes between crawling feeds") + flag.IntVarP(&minutes, "minutes", "m", 60, "minutes between crawling feeds") flag.BoolVarP(&proxyImages, "imageproxy", "i", false, "rewrite and proxy all image requests for privacy (experimental)") flag.BoolVarP(&verbose, "verbose", "v", false, "verbose output") @@ -66,29 +67,27 @@ func main() { return } - // - // this doesn't seem quite right yet // will revise - // go func() { - // // ticker := time.NewTicker(time.Second*5) - // if minutes < 1 { - // return - // } - // ticker := time.NewTicker(time.Minute * time.Duration(minutes)) - // defer ticker.Stop() - // done := make(chan bool) - // for { - // select { - // case <-done: - // fmt.Println("done") - // return - // case t := <-ticker.C: - // vlog.Printf("starting crawl at %s\n", t) - // crawler.Crawl() - // } - // } - // }() - + go backgroundCrawl(minutes) vlog.Printf("starting web server at 127.0.0.1:%d\n", config.Config.Port) web.Serve() } + +func backgroundCrawl(minutes int) { + if minutes < 1 { + return + } + ticker := time.NewTicker(time.Minute * time.Duration(minutes)) + defer ticker.Stop() + done := make(chan bool) + for { + select { + case <-done: + fmt.Println("done") + return + case t := <-ticker.C: + vlog.Printf("starting crawl at %s\n", t) + crawler.Crawl() + } + } +} |