forked from chararch/gobatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.go
59 lines (48 loc) · 1.18 KB
/
global.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
package batch
import (
"database/sql"
"github.com/supreness/batch/internal/logs"
"os"
)
//log
var logger logs.Logger = logs.NewLogger(os.Stdout, logs.Info)
//SetLogger set a logger instance for GoBatch
func SetLogger(l logs.Logger) {
logger = l
}
//task pool
const (
DefaultJobPoolSize = 10
DefaultStepTaskPoolSize = 1000
)
var jobPool = newTaskPool(DefaultJobPoolSize)
var stepPool = newTaskPool(DefaultStepTaskPoolSize)
//SetMaxRunningJobs set max number of parallel jobs for GoBatch
func SetMaxRunningJobs(size int) {
jobPool.SetMaxSize(size)
}
//SetMaxRunningSteps set max number of parallel steps for GoBatch
func SetMaxRunningSteps(size int) {
stepPool.SetMaxSize(size)
}
//db
var db *sql.DB
//SetDB register a *sql.DB instance for GoBatch
func SetDB(sqlDb *sql.DB) {
if sqlDb == nil {
panic("sqlDb must not be nil")
}
db = sqlDb
if txManager == nil {
txManager = &DefaultTxManager{sqlDb}
}
}
//transaction manager
var txManager TransactionManager
//SetTransactionManager register a TransactionManager instance for GoBatch
func SetTransactionManager(txMgr TransactionManager) {
if txMgr == nil {
panic("transaction manager must not be nil")
}
txManager = txMgr
}