From 9511ccc7e0cfac59c7f0ba0e89aa794455369941 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Wed, 4 Jul 2018 16:24:44 -0700 Subject: crawl feeds in background while web ui runs --- main.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 06700b6..c860653 100644 --- a/main.go +++ b/main.go @@ -9,13 +9,14 @@ import ( "adammathes.com/neko/vlog" "adammathes.com/neko/web" "fmt" + "time" flag "github.com/ogier/pflag" ) 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") @@ -26,12 +27,12 @@ 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.BoolVarP(&proxyImages, "imageproxy", "i", false, "rewrite and proxy all image requests for privacy (experimental)") flag.BoolVarP(&verbose, "verbose", "v", false, "verbose output") // passwords on command line are bad flag.StringVarP(&password, "password", "p", "", "password to access web interface") - flag.Parse() if help { @@ -63,11 +64,28 @@ func main() { return } - // if password == "" { - // panic("Please specify an access password\n") - // } + 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() + } + } + }() + vlog.Printf("starting web server at 127.0.0.1:%d\n", config.Config.Port) web.Serve() - } + -- cgit v1.2.3