daemon: DaemonStatus + JobStatus + dummy implementation

refs #10
This commit is contained in:
Christian Schwarz 2017-12-24 15:34:41 +01:00
parent 2c87b15e83
commit 8c7e373049
5 changed files with 56 additions and 2 deletions

View File

@ -32,6 +32,10 @@ func (j *ControlJob) JobName() string {
return j.Name
}
func (j *ControlJob) JobStatus(ctx context.Context) (*JobStatus, error) {
return &JobStatus{}, nil
}
const (
ControlJobEndpointProfile string = "/debug/pprof/profile"
ControlJobEndpointVersion string = "/version"

View File

@ -173,6 +173,10 @@ outer:
}
func (j *LocalJob) JobStatus(ctxt context.Context) (*JobStatus, error) {
return &JobStatus{}, nil
}
func (j *LocalJob) Pruner(side PrunePolicySide, dryRun bool) (p Pruner, err error) {
var dsfilter zfs.DatasetFilter

View File

@ -149,6 +149,10 @@ start:
}
func (j *PullJob) JobStatus(ctxt context.Context) (*JobStatus, error) {
return &JobStatus{}, nil
}
func (j *PullJob) Pruner(side PrunePolicySide, dryRun bool) (p Pruner, err error) {
p = Pruner{
time.Now(),

View File

@ -108,6 +108,10 @@ outer:
}
func (j *SourceJob) JobStatus(ctxt context.Context) (*JobStatus, error) {
return &JobStatus{}, nil
}
func (j *SourceJob) Pruner(side PrunePolicySide, dryRun bool) (p Pruner, err error) {
p = Pruner{
time.Now(),

View File

@ -29,6 +29,7 @@ func init() {
type Job interface {
JobName() string
JobStart(ctxt context.Context)
JobStatus(ctxt context.Context) (*JobStatus, error)
}
func doDaemon(cmd *cobra.Command, args []string) {
@ -59,14 +60,17 @@ const (
type Daemon struct {
conf *Config
startedAt time.Time
}
func NewDaemon(initialConf *Config) *Daemon {
return &Daemon{initialConf}
return &Daemon{conf: initialConf}
}
func (d *Daemon) Loop(ctx context.Context) {
d.startedAt = time.Now()
log := ctx.Value(contextKeyLog).(Logger)
ctx, cancel := context.WithCancel(ctx)
@ -114,6 +118,39 @@ outer:
}
// Representation of a Job's status that is composed of Tasks
type JobStatus struct {
// Statuses of all tasks of this job
Tasks []*TaskStatus
// Error != "" if JobStatus() returned an error
JobStatusError string
}
// Representation of a Daemon's status that is composed of Jobs
type DaemonStatus struct {
StartedAt time.Time
Jobs map[string]*JobStatus
}
func (d *Daemon) Status() (s *DaemonStatus) {
s = &DaemonStatus{}
s.StartedAt = d.startedAt
s.Jobs = make(map[string]*JobStatus, len(d.conf.Jobs))
for name, j := range d.conf.Jobs {
status, err := j.JobStatus(context.TODO())
if err != nil {
s.Jobs[name] = &JobStatus{nil, err.Error()}
continue
}
s.Jobs[name] = status
}
return
}
// Representation of a Task's status
type TaskStatus struct {
Name string
@ -337,4 +374,5 @@ func (u *IOProgressUpdater) Read(p []byte) (n int, err error) {
n, err = u.r.Read(p)
u.p.UpdateIO(int64(n), 0)
return
}