forked from sjkhsl/study_xxqg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
43 lines (35 loc) · 792 Bytes
/
run.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
package main
import (
"sync"
"github.com/panjf2000/ants/v2"
log "github.com/sirupsen/logrus"
"github.com/sjkhsl/study_xxqg/lib"
"github.com/sjkhsl/study_xxqg/lib/state"
"github.com/sjkhsl/study_xxqg/model"
)
type Task struct {
Core *lib.Core
User *model.User
wg *sync.WaitGroup
}
var (
pool *ants.PoolWithFunc
)
func run(task *Task) {
pool.Invoke(task)
}
func initTask() {
pool1, err := ants.NewPoolWithFunc(config.PoolSize, func(i2 interface{}) {
task := i2.(*Task)
log.Infoln("开始执行" + task.User.Nick)
state.Add(task.User.Uid, task.Core)
lib.Study(task.Core, task.User)
defer task.Core.Quit()
defer state.Delete(task.User.Uid)
task.wg.Done()
})
if err != nil {
log.Errorln("创建定时任务协程池失败" + err.Error())
}
pool = pool1
}