start implementing new daemon in package daemon

This commit is contained in:
Christian Schwarz
2018-08-27 19:10:55 +02:00
parent c7237cb09d
commit 89dc267780
11 changed files with 1158 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
package job
import (
"github.com/zrepl/zrepl/cmd/config"
"fmt"
)
func JobsFromConfig(c config.Config) ([]Job, error) {
js := make([]Job, len(c.Jobs))
for i := range c.Jobs {
j, err := buildJob(c.Global, c.Jobs[i])
if err != nil {
return nil, err
}
js[i] = j
}
return js, nil
}
func buildJob(c config.Global, in config.JobEnum) (j Job, err error) {
switch v := in.Ret.(type) {
default:
panic(fmt.Sprintf("implementation error: unknown job type %s", v))
}
}
+47
View File
@@ -0,0 +1,47 @@
package job
import (
"context"
"github.com/zrepl/zrepl/logger"
)
type Logger = logger.Logger
type contextKey int
const (
contextKeyLog contextKey = iota
contextKeyWakeup
)
func GetLogger(ctx context.Context) Logger {
if l, ok := ctx.Value(contextKeyLog).(Logger); ok {
return l
}
return logger.NewNullLogger()
}
func WithLogger(ctx context.Context, l Logger) context.Context {
return context.WithValue(ctx, contextKeyLog, l)
}
func WithWakeup(ctx context.Context) (context.Context, WakeupChan) {
wc := make(chan struct{}, 1)
return context.WithValue(ctx, contextKeyWakeup, wc), wc
}
type Job interface {
Name() string
Run(ctx context.Context)
Status() interface{}
}
type WakeupChan <-chan struct{}
func WaitWakeup(ctx context.Context) WakeupChan {
wc, ok := ctx.Value(contextKeyWakeup).(WakeupChan)
if !ok {
wc = make(chan struct{})
}
return wc
}