mirror of
https://github.com/zrepl/zrepl.git
synced 2025-04-10 19:38:16 +02:00
parent
d13c6e3fc3
commit
4b3d83ec1f
@ -172,6 +172,8 @@ type TaskStatus struct {
|
|||||||
// The maximum log level of LogEntries.
|
// The maximum log level of LogEntries.
|
||||||
// Only valid if len(LogEntries) > 0.
|
// Only valid if len(LogEntries) > 0.
|
||||||
MaxLogLevel logger.Level
|
MaxLogLevel logger.Level
|
||||||
|
// Last time something about the Task changed
|
||||||
|
LastUpdate time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// An instance of Task tracks a single thread of activity that is part of a Job.
|
// An instance of Task tracks a single thread of activity that is part of a Job.
|
||||||
@ -179,6 +181,8 @@ type Task struct {
|
|||||||
// Stack of activities the task is currently in
|
// Stack of activities the task is currently in
|
||||||
// Members are instances of taskActivity
|
// Members are instances of taskActivity
|
||||||
activities *list.List
|
activities *list.List
|
||||||
|
// Last time activities was changed (not the activities inside, the list)
|
||||||
|
activitiesLastUpdate time.Time
|
||||||
// Protects Task members from modification
|
// Protects Task members from modification
|
||||||
rwl sync.RWMutex
|
rwl sync.RWMutex
|
||||||
}
|
}
|
||||||
@ -291,6 +295,7 @@ func (t *Task) Enter(activity string) {
|
|||||||
activityField := strings.Join(stack, ".")
|
activityField := strings.Join(stack, ".")
|
||||||
act.logger = prev.logger.ReplaceField(logTaskField, activityField)
|
act.logger = prev.logger.ReplaceField(logTaskField, activityField)
|
||||||
|
|
||||||
|
t.activitiesLastUpdate = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) UpdateProgress(dtx, drx int64) {
|
func (t *Task) UpdateProgress(dtx, drx int64) {
|
||||||
@ -325,6 +330,11 @@ func (t *Task) Status() *TaskStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastUpdate := prog.lastUpdate
|
||||||
|
if lastUpdate.Before(t.activitiesLastUpdate) {
|
||||||
|
lastUpdate = t.activitiesLastUpdate
|
||||||
|
}
|
||||||
|
|
||||||
s := &TaskStatus{
|
s := &TaskStatus{
|
||||||
Name: stack[0],
|
Name: stack[0],
|
||||||
ActivityStack: stack,
|
ActivityStack: stack,
|
||||||
@ -333,6 +343,7 @@ func (t *Task) Status() *TaskStatus {
|
|||||||
ProgressTx: prog.tx,
|
ProgressTx: prog.tx,
|
||||||
LogEntries: prog.logEntries,
|
LogEntries: prog.logEntries,
|
||||||
MaxLogLevel: maxLevel,
|
MaxLogLevel: maxLevel,
|
||||||
|
LastUpdate: lastUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
@ -348,6 +359,7 @@ func (t *Task) Finish() {
|
|||||||
return // cannot remove root activity
|
return // cannot remove root activity
|
||||||
}
|
}
|
||||||
t.activities.Remove(top)
|
t.activities.Remove(top)
|
||||||
|
t.activitiesLastUpdate = time.Now()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,6 +368,7 @@ func (t *Task) Finish() {
|
|||||||
func (t *Task) Log() *logger.Logger {
|
func (t *Task) Log() *logger.Logger {
|
||||||
t.rwl.RLock()
|
t.rwl.RLock()
|
||||||
defer t.rwl.RUnlock()
|
defer t.rwl.RUnlock()
|
||||||
|
// FIXME should influence TaskStatus's LastUpdate field
|
||||||
return t.cur().logger
|
return t.cur().logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user