-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
40 lines (35 loc) · 943 Bytes
/
job.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
package worker
import (
"github.com/mmanjoura/adsa-cms/admin"
"github.com/mmanjoura/adsa-cms/qor"
"github.com/mmanjoura/adsa-cms/roles"
)
// Job is a struct that hold Qor Job definations
type Job struct {
Name string
Group string
Handler func(interface{}, QorJobInterface) error
Permission *roles.Permission
Queue Queue
Resource *admin.Resource
Worker *Worker
}
// NewStruct initialize job struct
func (job *Job) NewStruct() interface{} {
qorJobInterface := job.Worker.JobResource.NewStruct().(QorJobInterface)
qorJobInterface.SetJob(job)
return qorJobInterface
}
// GetQueue get defined job's queue
func (job *Job) GetQueue() Queue {
if job.Queue != nil {
return job.Queue
}
return job.Worker.Queue
}
func (job Job) HasPermission(mode roles.PermissionMode, context *qor.Context) bool {
if job.Permission == nil {
return true
}
return job.Permission.HasPermission(mode, context.Roles...)
}