submitqueue.submitqueue: document Result functions
This commit is contained in:
		
							parent
							
								
									fdfcf7967a
								
							
						
					
					
						commit
						192835278c
					
				
					 1 changed files with 11 additions and 0 deletions
				
			
		|  | @ -159,6 +159,9 @@ func (s *SubmitQueue) DoRebase(log *logrus.Logger) error { | ||||||
| // Problem: no inspection during the run | // Problem: no inspection during the run | ||||||
| // Problem: record the state | // Problem: record the state | ||||||
| 
 | 
 | ||||||
|  | // Result all data necessary to inspect a previous run | ||||||
|  | // This includes the Series from that run, and all Log Entries collected. | ||||||
|  | // It also implements the interface required for logrus.Hook. | ||||||
| type Result struct { | type Result struct { | ||||||
| 	LogEntries []*logrus.Entry | 	LogEntries []*logrus.Entry | ||||||
| 	Series     []Serie | 	Series     []Serie | ||||||
|  | @ -166,16 +169,20 @@ type Result struct { | ||||||
| 	startTime  time.Time | 	startTime  time.Time | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // MakeResult produces a new Result struct, | ||||||
|  | // and initializes startTime with the current time. | ||||||
| func MakeResult() *Result { | func MakeResult() *Result { | ||||||
| 	return &Result{ | 	return &Result{ | ||||||
| 		startTime: time.Now(), | 		startTime: time.Now(), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // StartTime returns the startTime | ||||||
| func (r Result) StartTime() time.Time { | func (r Result) StartTime() time.Time { | ||||||
| 	return r.startTime | 	return r.startTime | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // EndTime returns the time of the latest log entry | ||||||
| func (r Result) EndTime() time.Time { | func (r Result) EndTime() time.Time { | ||||||
| 	if len(r.LogEntries) == 0 { | 	if len(r.LogEntries) == 0 { | ||||||
| 		return r.startTime | 		return r.startTime | ||||||
|  | @ -183,11 +190,15 @@ func (r Result) EndTime() time.Time { | ||||||
| 	return r.LogEntries[len(r.LogEntries)-1].Time | 	return r.LogEntries[len(r.LogEntries)-1].Time | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Fire is called by logrus on each log event, | ||||||
|  | // we collect all log entries in the struct variable | ||||||
| func (r *Result) Fire(entry *logrus.Entry) error { | func (r *Result) Fire(entry *logrus.Entry) error { | ||||||
| 	r.LogEntries = append(r.LogEntries, entry) | 	r.LogEntries = append(r.LogEntries, entry) | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Levels is called by logrus to determine whether to Fire the handler. | ||||||
|  | // As we want to collect all log entries, we return logrus.AllLevels | ||||||
| func (r *Result) Levels() []logrus.Level { | func (r *Result) Levels() []logrus.Level { | ||||||
| 	return logrus.AllLevels | 	return logrus.AllLevels | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue