From 0895e0284413bbf9ecffe107c9c6b8da1c6f5596 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Thu, 5 Apr 2018 22:18:22 +0200 Subject: [PATCH] daemon: Task: track relation to parent job refs #67 --- cmd/config_job_local.go | 10 +++++----- cmd/config_job_pull.go | 2 +- cmd/config_job_source.go | 6 +++--- cmd/daemon.go | 5 ++++- cmd/test.go | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/config_job_local.go b/cmd/config_job_local.go index d52b34e..2d56530 100644 --- a/cmd/config_job_local.go +++ b/cmd/config_job_local.go @@ -88,11 +88,11 @@ func (j *LocalJob) JobStart(ctx context.Context) { rootLog := ctx.Value(contextKeyLog).(Logger) - j.snapperTask = NewTask("snapshot", rootLog) - j.mainTask = NewTask("main", rootLog) - j.handlerTask = NewTask("handler", rootLog) - j.pruneRHSTask = NewTask("prune_rhs", rootLog) - j.pruneLHSTask = NewTask("prune_lhs", rootLog) + j.snapperTask = NewTask("snapshot", j, rootLog) + j.mainTask = NewTask("main", j, rootLog) + j.handlerTask = NewTask("handler", j, rootLog) + j.pruneRHSTask = NewTask("prune_rhs", j, rootLog) + j.pruneLHSTask = NewTask("prune_lhs", j, rootLog) local := rpc.NewLocalRPC() // Allow access to any dataset since we control what mapping diff --git a/cmd/config_job_pull.go b/cmd/config_job_pull.go index 4c32bf0..e3201f0 100644 --- a/cmd/config_job_pull.go +++ b/cmd/config_job_pull.go @@ -98,7 +98,7 @@ func (j *PullJob) JobStart(ctx context.Context) { log := ctx.Value(contextKeyLog).(Logger) defer log.Info("exiting") - j.task = NewTask("main", log) + j.task = NewTask("main", j, log) // j.task is idle here idle here diff --git a/cmd/config_job_source.go b/cmd/config_job_source.go index ed95d17..ba43186 100644 --- a/cmd/config_job_source.go +++ b/cmd/config_job_source.go @@ -81,9 +81,9 @@ func (j *SourceJob) JobStart(ctx context.Context) { log := ctx.Value(contextKeyLog).(Logger) defer log.Info("exiting") - j.autosnapTask = NewTask("autosnap", log) - j.pruneTask = NewTask("prune", log) - j.serveTask = NewTask("serve", log) + j.autosnapTask = NewTask("autosnap", j, log) + j.pruneTask = NewTask("prune", j, log) + j.serveTask = NewTask("serve", j, log) a := IntervalAutosnap{j.autosnapTask, j.Filesystems, j.SnapshotPrefix, j.Interval} p, err := j.Pruner(j.pruneTask, PrunePolicySideDefault, false) diff --git a/cmd/daemon.go b/cmd/daemon.go index cedb20b..c4dfb69 100644 --- a/cmd/daemon.go +++ b/cmd/daemon.go @@ -178,6 +178,8 @@ type TaskStatus struct { // An instance of Task tracks a single thread of activity that is part of a Job. type Task struct { + parent Job // immutable + // Stack of activities the task is currently in // Members are instances of taskActivity activities *list.List @@ -250,8 +252,9 @@ type taskActivity struct { progress *taskProgress } -func NewTask(name string, lg *logger.Logger) *Task { +func NewTask(name string, parent Job, lg *logger.Logger) *Task { t := &Task{ + parent: parent, activities: list.New(), } rootLogger := lg.ReplaceField(logTaskField, name). diff --git a/cmd/test.go b/cmd/test.go index b92b489..d6b1f80 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -170,7 +170,7 @@ func doTestPrunePolicy(cmd *cobra.Command, args []string) { log.Printf("job dump:\n%s", pretty.Sprint(jobp)) - task := NewTask("", log) + task := NewTask("", jobi, log) pruner, err := jobp.Pruner(task, testPrunePolicyArgs.side, true) if err != nil { log.Printf("cannot create test pruner: %s", err)