WIP: states with updater func instead of direct locking

This commit is contained in:
Christian Schwarz
2018-08-16 01:26:09 +02:00
parent 991f13a3da
commit 094eced2c7
4 changed files with 187 additions and 155 deletions
+9 -16
View File
@@ -29,6 +29,7 @@ type PullJob struct {
Debug JobDebugSettings
task *Task
rep *replication.Replication
}
func parsePullJob(c JobParsingContext, name string, i map[string]interface{}) (j *PullJob, err error) {
@@ -186,26 +187,14 @@ func (j *PullJob) doRun(ctx context.Context) {
return
}
usr2 := make(chan os.Signal)
defer close(usr2)
signal.Notify(usr2, syscall.SIGUSR2)
defer signal.Stop(usr2)
retryNow := make(chan struct{}, 1) // buffered so we don't leak the goroutine
go func() {
for {
sig := <-usr2
if sig != nil {
retryNow <- struct{}{}
} else {
break
}
}
}()
ctx = replication.ContextWithLogger(ctx, replicationLogAdaptor{j.task.Log().WithField("subsystem", "replication")})
ctx = streamrpc.ContextWithLogger(ctx, streamrpcLogAdaptor{j.task.Log().WithField("subsystem", "rpc.protocol")})
ctx = context.WithValue(ctx, contextKeyLog, j.task.Log().WithField("subsystem", "rpc.endpoint"))
replication.Replicate(ctx, replication.NewEndpointPairPull(sender, puller), retryNow)
j.rep = &replication.Replication{}
retryNow := make(chan struct{})
j.rep.Drive(ctx, replication.NewEndpointPairPull(sender, puller), retryNow)
client.Close()
j.task.Finish()
@@ -221,6 +210,10 @@ func (j *PullJob) doRun(ctx context.Context) {
}
func (j *PullJob) Report() *replication.Report {
return j.rep.Report()
}
func (j *PullJob) JobStatus(ctxt context.Context) (*JobStatus, error) {
return &JobStatus{Tasks: []*TaskStatus{j.task.Status()}}, nil
}