WIP rewrite the daemon

cmd subdir does not build on purpose, it's only left in tree to grab old
code and move it to github.com/zrepl/zrepl/daemon
This commit is contained in:
Christian Schwarz
2018-08-27 22:21:45 +02:00
parent df6e1bc64d
commit c69ebd3806
55 changed files with 1133 additions and 84 deletions

View File

@ -3,7 +3,10 @@ package daemon
import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/job"
"github.com/zrepl/zrepl/daemon/logging"
"github.com/zrepl/zrepl/logger"
"github.com/zrepl/zrepl/version"
"os"
@ -12,12 +15,8 @@ import (
"sync"
"syscall"
"time"
"github.com/zrepl/zrepl/cmd/config"
"github.com/zrepl/zrepl/daemon/logging"
"github.com/pkg/errors"
)
func Run(conf config.Config) error {
ctx, cancel := context.WithCancel(context.Background())
@ -86,13 +85,13 @@ type jobs struct {
// m protects all fields below it
m sync.RWMutex
wakeups map[string]job.WakeupChan // by JobName
wakeups map[string]job.WakeupFunc // by Job.Name
jobs map[string]job.Job
}
func newJobs() *jobs {
return &jobs{
wakeups: make(map[string]job.WakeupChan),
wakeups: make(map[string]job.WakeupFunc),
jobs: make(map[string]job.Job),
}
}
@ -137,6 +136,17 @@ func (s *jobs) status() map[string]interface{} {
return ret
}
func (s *jobs) wakeup(job string) error {
s.m.RLock()
defer s.m.RUnlock()
wu, ok := s.wakeups[job]
if !ok {
return errors.Errorf("Job %s does not exist", job)
}
return wu()
}
const (
jobNamePrometheus = "_prometheus"
jobNameControl = "_control"