aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-07-06 20:53:17 -0700
committerAdam Mathes <adam@trenchant.org>2018-07-06 20:53:17 -0700
commitcdc1f64031af949874fed73e1d51247dd4226660 (patch)
tree68d4ff3a06d28518ef648e7740e674e158a87029
parentc8bf5665f43d54dd61f90629d101b954dafe3c89 (diff)
downloadneko-cdc1f64031af949874fed73e1d51247dd4226660.tar.gz
neko-cdc1f64031af949874fed73e1d51247dd4226660.tar.bz2
neko-cdc1f64031af949874fed73e1d51247dd4226660.zip
try background crawler again
-rw-r--r--main.go47
1 files changed, 23 insertions, 24 deletions
diff --git a/main.go b/main.go
index 8d417ad..9e5b180 100644
--- a/main.go
+++ b/main.go
@@ -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()
+ }
+ }
+}