fix: stream platform builder progress
This commit is contained in:
@@ -88,7 +88,16 @@ func (svc *CoreService) executeDistributionBuild(job domain.Job) error {
|
||||
if isTerminalJobState(job.State) {
|
||||
return nil
|
||||
}
|
||||
payload, buildErr := svc.configuredDistributionBuilder().Build(input)
|
||||
builder := svc.configuredDistributionBuilder()
|
||||
var payload []byte
|
||||
var buildErr error
|
||||
if progressBuilder, ok := builder.(distributionBuilderWithProgress); ok {
|
||||
payload, buildErr = progressBuilder.BuildWithProgress(input, func(progress DistributionBuildProgress) {
|
||||
_ = svc.updateDistributionBuildProgress(job, progress)
|
||||
})
|
||||
} else {
|
||||
payload, buildErr = builder.Build(input)
|
||||
}
|
||||
if buildErr != nil {
|
||||
return svc.failDistributionBuildJob(job, builderJobFailureMessage(buildErr))
|
||||
}
|
||||
@@ -432,7 +441,7 @@ func (svc *CoreService) markDistributionBuildRunning(job *domain.Job) error {
|
||||
}
|
||||
current.State = domain.JobStateRunning
|
||||
current.Attempt = maxInt(current.Attempt, 1)
|
||||
current.Progress = domain.JobProgress{Percent: 5, Phase: current.Progress.Phase, Message: "platform builder started"}
|
||||
current.Progress = domain.JobProgress{Percent: 5, Phase: current.Progress.Phase, Message: "env_check: platform builder started"}
|
||||
current.UpdatedAt = stamp
|
||||
if err := svc.updateScheduledJob(current); err != nil {
|
||||
return err
|
||||
@@ -444,6 +453,29 @@ func (svc *CoreService) markDistributionBuildRunning(job *domain.Job) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (svc *CoreService) updateDistributionBuildProgress(job domain.Job, progress DistributionBuildProgress) error {
|
||||
stamp := svc.now()
|
||||
svc.jobMu.Lock()
|
||||
defer svc.jobMu.Unlock()
|
||||
|
||||
current, err := svc.store.Jobs().Get(job.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if isTerminalJobState(current.State) {
|
||||
return nil
|
||||
}
|
||||
if progress.Percent < current.Progress.Percent {
|
||||
progress.Percent = current.Progress.Percent
|
||||
}
|
||||
current.Progress = domain.JobProgress{Percent: progress.Percent, Phase: current.Progress.Phase, Message: strings.TrimSpace(progress.Message)}
|
||||
current.UpdatedAt = stamp
|
||||
if err := svc.updateScheduledJob(current); err != nil {
|
||||
return err
|
||||
}
|
||||
return svc.projectDistributionBuildProgress(current, stamp)
|
||||
}
|
||||
|
||||
func (svc *CoreService) succeedDistributionBuildJob(job domain.Job, artifactID string) error {
|
||||
stamp := svc.now()
|
||||
svc.jobMu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user