forked from hezhizheng/go-movies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1b986b
commit cecbbd7
Showing
5 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,9 @@ func main() { | |
|
||
firstSpider() | ||
|
||
// 启动定时爬虫任务 | ||
utils.TimingSpider() | ||
|
||
log.Println(http.ListenAndServe(port, router)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/robfig/cron/v3" | ||
"github.com/spf13/viper" | ||
"log" | ||
) | ||
|
||
func TimingSpider() { | ||
|
||
log.Println("cron TimingSpider start:") | ||
|
||
// v3 用法 干 | ||
c := cron.New(cron.WithSeconds()) | ||
|
||
// 每天定时执行的条件 | ||
spec := viper.GetString(`cron.timing_spider`) | ||
|
||
c.AddFunc(spec, func() { | ||
go StartSpider() | ||
log.Println("Spider ing:") | ||
}) | ||
|
||
go c.Start() | ||
|
||
// 关闭计划任务, 但是不能关闭已经在执行中的任务. | ||
// defer c.Stop() | ||
|
||
// 阻塞 | ||
//select {} | ||
} |