Fix job duration counting

parent cde4a2d1
Pipeline #31273931 passed with stages
in 39 minutes and 49 seconds
......@@ -57,32 +57,33 @@ func (c *ExecCommand) createBuild(repoURL string, abortSignal chan os.Signal) (b
return
}
build = &common.Build{
JobResponse: common.JobResponse{
ID: 1,
Token: "",
AllowGitFetch: false,
JobInfo: common.JobInfo{
Name: "",
Stage: "",
ProjectID: 1,
ProjectName: "",
},
GitInfo: common.GitInfo{
RepoURL: repoURL,
Ref: strings.TrimSpace(refName),
Sha: strings.TrimSpace(sha),
BeforeSha: strings.TrimSpace(beforeSha),
},
RunnerInfo: common.RunnerInfo{
Timeout: c.getTimeout(),
},
jobResponse := common.JobResponse{
ID: 1,
Token: "",
AllowGitFetch: false,
JobInfo: common.JobInfo{
Name: "",
Stage: "",
ProjectID: 1,
ProjectName: "",
},
Runner: &common.RunnerConfig{
RunnerSettings: c.RunnerSettings,
GitInfo: common.GitInfo{
RepoURL: repoURL,
Ref: strings.TrimSpace(refName),
Sha: strings.TrimSpace(sha),
BeforeSha: strings.TrimSpace(beforeSha),
},
SystemInterrupt: abortSignal,
RunnerInfo: common.RunnerInfo{
Timeout: c.getTimeout(),
},
}
runner := &common.RunnerConfig{
RunnerSettings: c.RunnerSettings,
}
build = common.NewBuild(jobResponse, runner, abortSignal, nil)
return
}
......
......@@ -182,13 +182,8 @@ func (mr *RunCommand) processRunner(id int, runner *common.RunnerConfig, runners
trace.SetFailuresCollector(mr.failuresCollector)
// Create a new build
build := &common.Build{
JobResponse: *jobData,
Runner: runner,
ExecutorData: context,
SystemInterrupt: mr.abortBuilds,
Session: buildSession,
}
build := common.NewBuild(*jobData, runner, mr.abortBuilds, context)
build.Session = buildSession
// Add build to list of builds to assign numbers
mr.buildsHelper.addBuild(build)
......
......@@ -87,13 +87,7 @@ func (r *RunSingleCommand) processBuild(data common.ExecutorData, abortSignal ch
}
config := common.NewConfig()
newBuild := common.Build{
JobResponse: *jobData,
Runner: &r.RunnerConfig,
SystemInterrupt: abortSignal,
ExecutorData: data,
}
newBuild := common.NewBuild(*jobData, &r.RunnerConfig, abortSignal, data)
jobCredentials := &common.JobCredentials{
ID: jobData.ID,
......
......@@ -88,7 +88,7 @@ type Build struct {
logger BuildLogger
allVariables JobVariables
startedAt time.Time
createdAt time.Time
}
func (b *Build) Log() *logrus.Entry {
......@@ -293,8 +293,6 @@ func (b *Build) run(ctx context.Context, executor Executor) (err error) {
buildFinish <- b.executeScript(runContext, executor)
}()
b.startedAt = time.Now()
// Wait for signals: cancel, timeout, abort or finish
b.Log().Debugln("Waiting for signals...")
select {
......@@ -645,5 +643,15 @@ func (b *Build) GetCacheRequestTimeout() int {
}
func (b *Build) Duration() time.Duration {
return time.Since(b.startedAt)
return time.Since(b.createdAt)
}
func NewBuild(jobData JobResponse, runnerConfig *RunnerConfig, systemInterrupt chan os.Signal, executorData ExecutorData) *Build {
return &Build{
JobResponse: jobData,
Runner: runnerConfig,
SystemInterrupt: systemInterrupt,
ExecutorData: executorData,
createdAt: time.Now(),
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment