-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
74 lines (62 loc) · 1.76 KB
/
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
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
package database
import (
"time"
"github.com/google/uuid"
"github.com/gopi-frame/contract/queue"
"github.com/gopi-frame/dao"
"gorm.io/gen/field"
)
// Job job model
type Job struct {
dao.DAO[Job] `gorm:"-"`
JobID uint64 `gorm:"column:id;autoIncrement;primaryKey;not null"`
JobUUID uuid.UUID `gorm:"column:uuid;uniqueIndex;not null"`
Queue string `gorm:"column:queue;not null"`
JobPayload queue.Job `gorm:"column:payload;serializer:json;not null"`
JobAttempts uint8 `gorm:"column:attempts;default:0"`
ReservedAt *time.Time `gorm:"column:reserved_at"`
AvaliableAt *time.Time `gorm:"column:avaliable_at;not null"`
CreatedAt *time.Time `gorm:"column:created_at;not null;autoCreateTime"`
}
// JobDAO job dao
type JobDAO struct {
dao.DAO[Job]
ID field.Uint64
UUID field.String
Queue field.String
Payload field.String
Attempts field.Uint8
ReservedAt field.Time
AvaliableAt field.Time
CreatedAt field.Time
}
// ID id
func (j *Job) ID() uint64 {
return j.JobID
}
// UUID uuid
func (j *Job) UUID() uuid.UUID {
return j.JobUUID
}
// Attempts attempts
func (j *Job) Attempts() uint {
return uint(j.JobAttempts)
}
// Payload payload
func (j *Job) Payload() queue.Job {
return j.JobPayload
}
// Fields fields
func (j Job) Fields(table string) JobDAO {
return JobDAO{
DAO: *(dao.DAO[Job]{}).UseTable(table),
ID: field.NewUint64(table, "id"),
UUID: field.NewString(table, "uuid"),
Queue: field.NewString(table, "queue"),
Payload: field.NewString(table, "payload"),
Attempts: field.NewUint8(table, "attempts"),
ReservedAt: field.NewTime(table, "reserved_at"),
AvaliableAt: field.NewTime(table, "avaliable_at"),
CreatedAt: field.NewTime(table, "created_at"),
}
}