-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (54 loc) · 1.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"carwer/enginee"
"carwer/persister/client"
"carwer/rpcsupport"
"carwer/scheduler"
"carwer/worker/client"
"carwer/zhenai/parser"
"flag"
"net/rpc"
"strings"
"github.com/cloudflare/cfssl/log"
)
var (
workerHosts = flag.String("worker hosts", "", "The workers hosts,split by comma")
persisterHost = flag.String("persister host", "", "The persister hosts")
)
func main() {
flag.Parse()
if *workerHosts == "" || *persisterHost == "" {
log.Error("The worker or persister host should set")
return
}
pool := createClientPool(strings.Split(*workerHosts, ","))
wokerProcess := client.CreateCrawerProcess(pool)
concurrency := enginee.Concurrency{
Scheduler: &scheduler.QueuedScheduler{},
WorkCount: 100,
ItemChan: persister.MakeItermSaver(*persisterHost),
WorkerProcess: wokerProcess,
}
concurrency.Run(enginee.Request{
URL: "http://www.zhenai.com/zhenghun",
Parser: enginee.NewParserFuncFactory("ParserCityList", parser.ParserCityList),
})
}
func createClientPool(hosts []string) chan *rpc.Client {
var clients []*rpc.Client
for _, host := range hosts {
c, err := rpcsupport.CreateRpcClient(host)
if err == nil {
clients = append(clients, c)
}
}
clientChan := make(chan *rpc.Client)
go func() {
for {
for _, c := range clients {
clientChan <- c
}
}
}()
return clientChan
}