-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
39 lines (31 loc) · 1.13 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
package main
import (
"log"
"time"
)
func main() {
// load configuration for application
loadConfigOrDie()
// 1.预处理器->解析url->urls(chan)-生产者
// 2.蜘蛛任务->得到results-tv(chan)*2 -(消费者,消费urls)+(生产者)
// 3.持久化引擎->消费results1-tv(chan)->持久化->消费者
// 4.下载器->消费results2-tv(chan)->下载model中的图片资源->消费者
urls := make(chan string, globalConfig().ChanSize)
results := make(chan Result, globalConfig().ChanSize)
resources := make(chan Resource, globalConfig().ChanSize)
//1.启动下载器任务
downLoadTask := CreateDownLoadTask("./download", resources)
go downLoadTask.Start()
//2.启动持久化任务
persistenceTask := CreatePersistenceTask(CreatePersistence(), results)
go persistenceTask.Start()
//3.启动蜘蛛任务
spiderTask := CreateSpiderTask(resources, results, urls)
go spiderTask.Start()
//4.启动预处理器任务
prepareTask := CreatePrepareTask(urls)
go prepareTask.Start()
executeTime := config.Duration
time.Sleep(config.Duration * time.Second)
log.Println("[爬虫程序退出]:爬取时间:", executeTime, "秒")
}