/
segment_command_state.go
41 lines (32 loc) · 1.09 KB
/
segment_command_state.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
package greenplum
import (
"fmt"
"path"
"time"
"github.com/apecloud/dataprotection-wal-g/internal"
"github.com/spf13/viper"
)
const stateFilesDirPrefix = "walg_seg_states"
const cmdStatePrefix = "cmd_run_state"
func FormatCmdStateName(contentID int, cmdName string) string {
return fmt.Sprintf("%s_%s_seg%d", cmdStatePrefix, cmdName, contentID)
}
func FormatCmdStatePath(contentID int, cmdName string) string {
return path.Join(FormatSegmentStateFolderPath(contentID), FormatCmdStateName(contentID, cmdName))
}
func FormatSegmentStateFolderPath(contentID int) string {
segStatesDirPath := viper.GetString(internal.GPSegmentStatesDir)
currSegmentStatePath := fmt.Sprintf("%s_seg%d", stateFilesDirPrefix, contentID)
return path.Join(segStatesDirPath, currSegmentStatePath)
}
type SegCmdStatus string
const (
RunningCmdStatus SegCmdStatus = "running"
FailedCmdStatus SegCmdStatus = "failed"
SuccessCmdStatus SegCmdStatus = "success"
InterruptedCmdStatus SegCmdStatus = "interrupted"
)
type SegCmdState struct {
TS time.Time `json:"ts"`
Status SegCmdStatus `json:"status"`
}