-
Notifications
You must be signed in to change notification settings - Fork 21
/
jobs.go
78 lines (65 loc) · 1.49 KB
/
jobs.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package core
import (
"gopkg.in/mgo.v2/bson"
)
// Job array type
type Jobs []*Job
func (n *Jobs) Init() (err error) {
for _, job := range *n {
changed, xerr := job.Init()
if xerr != nil {
err = xerr
return
}
if changed {
job.Save()
}
}
return
}
func (n *Jobs) RLockRecursive() {
for _, job := range *n {
job.RLockRecursive()
}
}
func (n *Jobs) RUnlockRecursive() {
for _, job := range *n {
job.RUnlockRecursive()
}
}
func (n *Jobs) GetAllUnsorted(q bson.M) (err error) {
_, err = dbFind(q, n, nil)
return
}
func (n *Jobs) GetAll(q bson.M, order string, direction string) (err error) {
if direction == "desc" {
order = "-" + order
}
_, err = dbFindSort(q, n, nil, order)
return
}
func (n *Jobs) GetPaginated(q bson.M, limit int, offset int, order string, direction string) (count int, err error) {
if direction == "desc" {
order = "-" + order
}
count, err = dbFindSort(q, n, map[string]int{"limit": limit, "offset": offset}, order)
return
}
func (n *Jobs) GetAllLimitOffset(q bson.M, limit int, offset int) (err error) {
_, err = dbFind(q, n, map[string]int{"limit": limit, "offset": offset})
return
}
func (n *Jobs) GetAllRecent(q bson.M, recent int) (count int, err error) {
count, err = dbFindSort(q, n, map[string]int{"limit": recent}, "-updatetime")
return
}
func (n *Jobs) GetJobAt(index int) *Job {
return (*n)[index]
}
func (n *Jobs) Length() int {
return len(*n)
}
func GetJobCount(q bson.M) (count int, err error) {
count, err = dbCount(q)
return
}