murphy/store/store.go

37 lines
773 B
Go
Raw Normal View History

2021-11-30 14:58:33 +01:00
package store
import (
2021-12-01 01:10:46 +01:00
"github.com/go-co-op/gocron"
2021-11-30 14:58:33 +01:00
"github.com/mehdioa/nlog"
2021-11-30 23:09:34 +01:00
"sync"
2021-11-30 14:58:33 +01:00
"time"
)
type Store struct {
2021-11-30 23:09:34 +01:00
TargetPath []string
SourcePath []string
2021-11-30 14:58:33 +01:00
GracePeriod time.Duration
2021-11-30 23:09:34 +01:00
Projects map[string]*Project
Logger *nlog.Logger
2021-12-01 01:10:46 +01:00
Scheduler *gocron.Scheduler
2021-11-30 23:09:34 +01:00
lock sync.RWMutex
2021-11-30 14:58:33 +01:00
}
2021-11-30 23:09:34 +01:00
type Project struct {
TargetPath string
LastChange time.Time
Created time.Time
ProjectName string
2021-12-01 01:10:46 +01:00
ShouldMove bool
2021-11-30 23:09:34 +01:00
Logger *nlog.Node
}
2021-12-01 01:10:46 +01:00
func NewStore(Logger *nlog.Logger, sourcePath []string, gracePeriod time.Duration) *Store {
store := &Store{Logger: Logger, Projects: make(map[string]*Project), SourcePath: sourcePath, GracePeriod: gracePeriod}
2021-11-30 14:58:33 +01:00
return store
}
2021-11-30 23:09:34 +01:00
func (store *Store) GetProjects() map[string]*Project {
return store.Projects
}