Skip to content

Commit

Permalink
feat: unified scheduling model (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge authored May 19, 2024
1 parent df4be0f commit 531cd28
Show file tree
Hide file tree
Showing 32 changed files with 1,149 additions and 513 deletions.
13 changes: 7 additions & 6 deletions backrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/garethgeorge/backrest/internal/api"
"github.com/garethgeorge/backrest/internal/auth"
"github.com/garethgeorge/backrest/internal/config"
"github.com/garethgeorge/backrest/internal/env"
"github.com/garethgeorge/backrest/internal/oplog"
"github.com/garethgeorge/backrest/internal/orchestrator"
"github.com/garethgeorge/backrest/internal/resticinstaller"
Expand Down Expand Up @@ -64,7 +65,7 @@ func main() {
var wg sync.WaitGroup

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

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

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

Expand Down Expand Up @@ -146,7 +147,7 @@ func init() {

func createConfigProvider() config.ConfigStore {
return &config.CachingValidatingStore{
ConfigStore: &config.JsonFileStore{Path: config.ConfigFilePath()},
ConfigStore: &config.JsonFileStore{Path: env.ConfigFilePath()},
}
}

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

func getSecret() []byte {
secretFile := path.Join(config.DataDir(), "jwt-secret")
secretFile := path.Join(env.DataDir(), "jwt-secret")
data, err := os.ReadFile(secretFile)
if err == nil {
zap.L().Debug("loading auth secret from file")
Expand All @@ -172,7 +173,7 @@ func getSecret() []byte {
if n, err := rand.Read(secret); err != nil || n != 64 {
zap.S().Fatalf("error generating secret: %v", err)
}
if err := os.MkdirAll(config.DataDir(), 0700); err != nil {
if err := os.MkdirAll(env.DataDir(), 0700); err != nil {
zap.S().Fatalf("error creating data directory: %v", err)
}
if err := os.WriteFile(secretFile, secret, 0600); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion docs/content/2.docs/2.hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ Variables
- `SnapshotId:string` - the snapshot ID associated with the operation or empty string if none is associated.
- `SnapshotStats:restic.BackupProgressEntry` - summary of the current backup operation. This is a struct. See examples below for details.
- `CurTime:time.Time` - the current time. This is a struct. Format as `{{ .FormatTime .CurTime }}`.
- `Duration:time.Duration` - the duration of the triggering operation. Format as `{{ .FormatDuration .Duration }}`.
- `Error:string` - the error message if an error occurred, or empty string if successful.

Functions

- `.Summary` - prints a default summary of the current event.
- `.FormatTime <time>` - formats a time.Time object e.g. as `2024-02-08T03:00:37Z`
- `.FormatTime <time>` - formats a time.Time object e.g. as `2024-02-08T03:00:37Z`.
- `.FormatDuration <duration>` - formats a time.Duration object e.g. as `1h2m3s`.
- `.FormatSizeBytes <int>` - formats a number as a size in bytes (e.g. 5MB, 10GB, 30TB, etc...)
- `.ShellEscape <string>` - escapes a string to safely be used in most shell environments. Should not be relied upon as secure for arbitrary input.
- `.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"`.
Expand Down
Loading

0 comments on commit 531cd28

Please sign in to comment.