diff options
author | Adam Mathes <adam@trenchant.org> | 2018-07-04 16:24:44 -0700 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2018-07-04 16:24:44 -0700 |
commit | 9511ccc7e0cfac59c7f0ba0e89aa794455369941 (patch) | |
tree | 04447884e76be25c4a025d71f13031de8203cf93 | |
parent | 11e0deecff0ca7d0d0ea26544528e65c38998ebd (diff) | |
download | neko-9511ccc7e0cfac59c7f0ba0e89aa794455369941.tar.gz neko-9511ccc7e0cfac59c7f0ba0e89aa794455369941.tar.bz2 neko-9511ccc7e0cfac59c7f0ba0e89aa794455369941.zip |
crawl feeds in background while web ui runs
-rw-r--r-- | main.go | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -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() - } + |