-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 994 Bytes
/
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
61
package main
import (
"os"
"time"
"vieclamit/broadcasts"
"vieclamit/database"
"vieclamit/feeds"
"vieclamit/handle"
repoimpl "vieclamit/repository/repo_impl"
"github.com/joho/godotenv"
)
func init() {
if err := godotenv.Load(".env"); err != nil {
return
}
}
func main() {
// conn db
mg := &database.Mongo{}
mg.CreateConn()
handle := handle.Handle{
Repo: repoimpl.NewRepo(mg),
}
// conn telegram
telegramConfig := &broadcasts.Telegram{
Token: os.Getenv("TELEGRAM_TOKEN"),
Repo: repoimpl.NewRepo(mg),
}
go telegramConfig.NewTelegram()
// run crawl
go feeds.TopCV(handle.Repo)
// schedule crawl
go schedule(6*time.Hour, handle, 1)
schedule(10*time.Hour, handle, 2)
}
func schedule(timeSchedule time.Duration, handle handle.Handle, index int) {
ticker := time.NewTicker(timeSchedule)
func() {
for {
switch index {
case 1:
<-ticker.C
feeds.TopCV(handle.Repo)
case 2:
<-ticker.C
handle.CheckJobDeadlineExpired()
}
}
}()
}