-
Notifications
You must be signed in to change notification settings - Fork 21
/
jobs.go
95 lines (80 loc) · 2.06 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package core
import (
"fmt"
"github.com/MG-RAST/AWE/lib/logger"
"gopkg.in/mgo.v2/bson"
)
// Job array type
type Jobs []*Job
func (n *Jobs) Init() (changed_count int, err error) {
changed_count = 0
for _, job := range *n {
changed, xerr := job.Init()
if xerr != nil {
err = fmt.Errorf("(jobs.Init) job.Init() returned %s", xerr.Error())
logger.Error(err.Error())
continue
//return
}
if changed {
changed_count += 1
err = job.Save()
if err != nil {
err = fmt.Errorf("(jobs.Init) job.Save() returns: %s", err.Error())
return
}
}
}
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, do_init bool) (err error) {
if direction == "desc" {
order = "-" + order
}
_, err = dbFindSort(q, n, nil, order, do_init)
return
}
func (n *Jobs) GetPaginated(q bson.M, limit int, offset int, order string, direction string, do_init bool) (count int, err error) {
if direction == "desc" {
order = "-" + order
}
count, err = dbFindSort(q, n, map[string]int{"limit": limit, "offset": offset}, order, do_init)
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, do_init bool) (count int, err error) {
count, err = dbFindSort(q, n, map[string]int{"limit": recent}, "-updatetime", do_init)
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
}
// patch the admin view data function from the job controller through to the db.go
func GetAdminView(special string) (data []interface{}, err error) {
data, err = dbAdminData(special)
return
}