feat: show step duration

This commit is contained in:
Jason Song
2022-11-01 18:14:20 +08:00
parent b4b22e78ad
commit b1da53286d
4 changed files with 51 additions and 2 deletions

View File

@ -6,6 +6,7 @@ package bots
import (
"context"
"time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
@ -32,6 +33,18 @@ func (TaskStep) TableName() string {
return "bots_task_step"
}
func (step *TaskStep) TakeTime() time.Duration {
if step.Started == 0 {
return 0
}
started := step.Started.AsTime()
if step.Status.IsDone() {
return step.Stopped.AsTime().Sub(started)
}
step.Stopped.AsTime().Sub(started)
return time.Since(started).Truncate(time.Second)
}
func init() {
db.RegisterModel(new(TaskStep))
}