aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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()
+ }
+ }
+}