-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjob.go
More file actions
47 lines (38 loc) · 777 Bytes
/
job.go
File metadata and controls
47 lines (38 loc) · 777 Bytes
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
package queue
import (
"fmt"
"reflect"
)
type Job interface {
Type() string
Data() interface{}
}
// reflectionJob is a thin wrapper for Jobs.
type reflectionJob struct {
body interface{}
}
// Data returns the enclosing data in the Job.
func (e reflectionJob) Data() interface{} {
return e.body
}
// Type returns the type JobFrom the Job as string.
func (e reflectionJob) Type() string {
bType := reflect.TypeOf(e.body)
return fmt.Sprintf("%s.%s", bType.PkgPath(), bType.Name())
}
type adHocJob struct {
t string
d interface{}
}
func (e adHocJob) Data() interface{} {
return e.d
}
func (e adHocJob) Type() string {
return e.t
}
// JobFrom wraps any struct, making it a valid Job.
func JobFrom(Job interface{}) Job {
return reflectionJob{
body: Job,
}
}