/
jobs.go
52 lines (44 loc) · 1.25 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
package torch
import (
"fmt"
"github.com/256dpi/fire/axe"
"github.com/256dpi/fire/coal"
"github.com/256dpi/fire/stick"
)
// ProcessJob defines a job that processes a single operation.
type ProcessJob struct {
axe.Base `json:"-" axe:"torch/process"`
Operation string `json:"operation"`
Model coal.ID `json:"model"`
}
// NewProcessJob creates and returns a new ProcessJob with a label.
func NewProcessJob(operation string, model coal.ID) *ProcessJob {
return &ProcessJob{
Base: axe.B(fmt.Sprintf("%s-%s", operation, model.Hex())),
Operation: operation,
Model: model,
}
}
// Validate implements the axe.Job interface.
func (j *ProcessJob) Validate() error {
return stick.Validate(j, func(v *stick.Validator) {
v.Value("Operation", false, stick.IsNotZero)
v.Value("Model", false, stick.IsNotZero)
})
}
// ScanJob defines a job that scans for due operations.
type ScanJob struct {
axe.Base `json:"-" axe:"torch/scan"`
Operation string `json:"operation"`
}
// NewScanJob creates and returns a new ScanJob with a label.
func NewScanJob(operation string) *ScanJob {
return &ScanJob{
Base: axe.B(operation),
Operation: operation,
}
}
// Validate implements the axe.Job interface.
func (j *ScanJob) Validate() error {
return nil
}