-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasis.go
More file actions
99 lines (76 loc) · 1.88 KB
/
basis.go
File metadata and controls
99 lines (76 loc) · 1.88 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"path/filepath"
"regexp"
"time"
"github.com/adrg/xdg"
)
const (
version = "0.3.0"
appDBFileName = "state.sqlite3"
appLockFileName = "app.lock"
appLogFileName = "app.log"
dirName = "regular"
globalEnvFileName = "global.env"
jobConfigFileName = "config.star"
jobEnvFileName = "job.env"
jobExecutableFileName = "./run"
stderrFileName = "stderr.log"
stdoutFileName = "stdout.log"
jobDirEnvVar = "REGULAR_JOB_DIR"
enableVar = "enable"
envVar = "env"
logVar = "log"
notifyModeVar = "notify"
oneDayVar = "one_day"
oneHourVar = "one_hour"
oneMinuteVar = "one_minute"
shouldRunVar = "should_run"
redactedValue = "[redacted]"
secretRegexp = "(?i)(key|password|secret|token)"
exitOK = 0
exitError = 1
exitBadUsage = 2
dirPerms = 0700
filePerms = 0600
timestampFormat = "2006-01-02 15:04:05 -0700"
debounceInterval = 100 * time.Millisecond
maxMissedTime = time.Hour
runInterval = time.Second
scheduleInterval = time.Minute
defaultLogLines = 10
maxLogBufferSize = 256 * 1024
)
var (
defaultConfigRoot = filepath.Join(xdg.ConfigHome, dirName)
defaultStateRoot = filepath.Join(xdg.StateHome, dirName)
)
type Config struct {
ConfigRoot string
StateRoot string
}
func jobDir(path string) string {
return filepath.Dir(path)
}
func jobNameFromPath(path string) string {
return filepath.Base(filepath.Dir(path))
}
func boolYesNo(b bool) string {
if b {
return "yes"
}
return "no"
}
// Format a Duration without the trailing zero units.
func formatDuration(d time.Duration) string {
d = d.Round(time.Millisecond)
if d > time.Second {
d = d.Round(100 * time.Millisecond)
}
zeroUnits := regexp.MustCompile("(^|[^0-9])(?:0h)?(?:0m)?(?:0s)?$")
s := zeroUnits.ReplaceAllString(d.String(), "$1")
if s == "" {
return "0"
}
return s
}