diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d13c162 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.log +*.pid + diff --git a/main.go b/main.go new file mode 100644 index 0000000..e8ed204 --- /dev/null +++ b/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "github.com/sevlyar/go-daemon" + "gitlab.com/saburly/kiviscraplib/structures" + "gitlab.com/saburly/kiviscraplib/webserver" + "log" +) + +var queue chan structures.Request +var end chan string + +// To terminate the daemon use: +// kill `cat sample.pid` +func main() { + cntxt := &daemon.Context{ + PidFileName: "sample.pid", + PidFilePerm: 0644, + LogFileName: "sample.log", + LogFilePerm: 0640, + WorkDir: "./", + Umask: 027, + Args: []string{"[kivi scraping load balancer]"}, + } + + d, err := cntxt.Reborn() + if err != nil { + log.Fatal("Unable to run: ", err) + } + if d != nil { + return + } + defer cntxt.Release() + + // todo: put queue length in env variable + queue = make(chan structures.Request, 1000) + end = make(chan string) + + go webserver.ServeHTTP(queue, end) + go func() { + for { + request := <-queue + //time.Sleep(2 * time.Second) + response := structures.Response{ + Url: request.Url, + Content: []byte("