Skip to content

Commit 531cd28

Browse files
authored
feat: unified scheduling model (#282)
1 parent df4be0f commit 531cd28

32 files changed

+1149
-513
lines changed

backrest.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/garethgeorge/backrest/internal/api"
2020
"github.com/garethgeorge/backrest/internal/auth"
2121
"github.com/garethgeorge/backrest/internal/config"
22+
"github.com/garethgeorge/backrest/internal/env"
2223
"github.com/garethgeorge/backrest/internal/oplog"
2324
"github.com/garethgeorge/backrest/internal/orchestrator"
2425
"github.com/garethgeorge/backrest/internal/resticinstaller"
@@ -64,7 +65,7 @@ func main() {
6465
var wg sync.WaitGroup
6566

6667
// Create / load the operation log
67-
oplogFile := path.Join(config.DataDir(), "oplog.boltdb")
68+
oplogFile := path.Join(env.DataDir(), "oplog.boltdb")
6869
oplog, err := oplog.NewOpLog(oplogFile)
6970
if err != nil {
7071
if !errors.Is(err, bbolt.ErrTimeout) {
@@ -76,7 +77,7 @@ func main() {
7677
defer oplog.Close()
7778

7879
// Create rotating log storage
79-
logStore := rotatinglog.NewRotatingLog(path.Join(config.DataDir(), "rotatinglogs"), 14) // 14 days of logs
80+
logStore := rotatinglog.NewRotatingLog(path.Join(env.DataDir(), "rotatinglogs"), 14) // 14 days of logs
8081
if err != nil {
8182
zap.S().Fatalf("error creating rotating log storage: %v", err)
8283
}
@@ -112,7 +113,7 @@ func main() {
112113

113114
// Serve the HTTP gateway
114115
server := &http.Server{
115-
Addr: config.BindAddress(),
116+
Addr: env.BindAddress(),
116117
Handler: h2c.NewHandler(mux, &http2.Server{}), // h2c is HTTP/2 without TLS for grpc-connect support.
117118
}
118119

@@ -146,7 +147,7 @@ func init() {
146147

147148
func createConfigProvider() config.ConfigStore {
148149
return &config.CachingValidatingStore{
149-
ConfigStore: &config.JsonFileStore{Path: config.ConfigFilePath()},
150+
ConfigStore: &config.JsonFileStore{Path: env.ConfigFilePath()},
150151
}
151152
}
152153

@@ -160,7 +161,7 @@ func onterm(s os.Signal, callback func()) {
160161
}
161162

162163
func getSecret() []byte {
163-
secretFile := path.Join(config.DataDir(), "jwt-secret")
164+
secretFile := path.Join(env.DataDir(), "jwt-secret")
164165
data, err := os.ReadFile(secretFile)
165166
if err == nil {
166167
zap.L().Debug("loading auth secret from file")
@@ -172,7 +173,7 @@ func getSecret() []byte {
172173
if n, err := rand.Read(secret); err != nil || n != 64 {
173174
zap.S().Fatalf("error generating secret: %v", err)
174175
}
175-
if err := os.MkdirAll(config.DataDir(), 0700); err != nil {
176+
if err := os.MkdirAll(env.DataDir(), 0700); err != nil {
176177
zap.S().Fatalf("error creating data directory: %v", err)
177178
}
178179
if err := os.WriteFile(secretFile, secret, 0600); err != nil {

docs/content/2.docs/2.hooks.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ Variables
3535
- `SnapshotId:string` - the snapshot ID associated with the operation or empty string if none is associated.
3636
- `SnapshotStats:restic.BackupProgressEntry` - summary of the current backup operation. This is a struct. See examples below for details.
3737
- `CurTime:time.Time` - the current time. This is a struct. Format as `{{ .FormatTime .CurTime }}`.
38+
- `Duration:time.Duration` - the duration of the triggering operation. Format as `{{ .FormatDuration .Duration }}`.
3839
- `Error:string` - the error message if an error occurred, or empty string if successful.
3940

4041
Functions
4142

4243
- `.Summary` - prints a default summary of the current event.
43-
- `.FormatTime <time>` - formats a time.Time object e.g. as `2024-02-08T03:00:37Z`
44+
- `.FormatTime <time>` - formats a time.Time object e.g. as `2024-02-08T03:00:37Z`.
45+
- `.FormatDuration <duration>` - formats a time.Duration object e.g. as `1h2m3s`.
4446
- `.FormatSizeBytes <int>` - formats a number as a size in bytes (e.g. 5MB, 10GB, 30TB, etc...)
4547
- `.ShellEscape <string>` - escapes a string to safely be used in most shell environments. Should not be relied upon as secure for arbitrary input.
4648
- `.JsonMarshal <any>` - attempts to marshall any value as JSON. Can also be used with literals e.g. to quote a string with escapes i.e. `hello"world` -becomes `"hello\"world"`.

0 commit comments

Comments
 (0)