-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunks.go
78 lines (70 loc) · 2.06 KB
/
chunks.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
package mdmstorage
import (
"encoding/json"
"fmt"
"time"
)
type ChunkState int
const (
// CPending means the task has just been created, waiting for processing.
CPending ChunkState = iota
// CRunning means DMD Director successfully got a pod and dispatched the sub-task to it.
CRunning
// CSucceeded means the entire task has been finished and has uploaded the output file to the correct Cloudflare address.
CSucceeded
// CFailed means the sub-task failed for some reason.
CFailed
)
func (s ChunkState) String() string {
res := ""
switch {
case s == CPending:
res = "pending"
case s == CRunning:
res = "running"
case s == CSucceeded:
res = "successed"
case s == CFailed:
res = "failed"
}
return res
}
type Chunk struct {
ID uint32 `gorm:"column:id;primaryKey"`
ChunkIndex uint32 `gorm:"column:chunk_index"`
TaskID string `gorm:"column:task_id"`
State ChunkState `gorm:"column:state"`
ResourceInfo string `gorm:"column:resource_info"`
RetryTimes uint8 `gorm:"column:retry_times"`
FinishedAt time.Time `gorm:"column:finished_at"`
StartedAt time.Time `gorm:"column:started_at"`
Origins string `gorm:"column:origins"`
Destinations string `gorm:"column:destinations"`
OriginIndex string `gorm:"column:origin_index"`
DestinationIndex string `gorm:"column:destination_index"`
CreateAt time.Time `gorm:"column:created_at"`
MetaStr string `gorm:"column:meta"`
Meta *Meta `gorm:"-"`
}
func (c *Chunk) FlattenToString() {
// flatten meta to string
if c.Meta == nil {
return
}
res, err := json.Marshal(c.Meta)
if err != nil {
c.MetaStr = fmt.Sprintf("failed to marshal task meta. mete:%v, err: %v", c.Meta, err)
return
}
c.MetaStr = string(res)
}
// TableName overrides the table name used by Task to `profiles`
func (c *Chunk) TableName() string {
return "mdm.chunks"
}
func (c *Chunk) SetFailureReason(reason string) {
if c.Meta == nil {
c.Meta = &Meta{}
}
c.Meta.FailureReason = reason
}