service/progress: newReplicatedJobProgressUpdater: slight cleanup

Use intermediate vars, so that the replicatedJobProgressUpdater can
be created in one go intead of setting some fields after the fact.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-02-03 15:35:26 +01:00
parent 4771abac9e
commit e88b1939f7
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -573,16 +573,17 @@ type replicatedJobProgressUpdater struct {
}
func newReplicatedJobProgressUpdater(service swarm.Service, progressOut progress.Output) *replicatedJobProgressUpdater {
u := &replicatedJobProgressUpdater{
progressOut: progressOut,
concurrent: int(*service.Spec.Mode.ReplicatedJob.MaxConcurrent),
total: int(*service.Spec.Mode.ReplicatedJob.TotalCompletions),
jobIteration: service.JobStatus.JobIteration.Index,
}
u.progressDigits = len(strconv.Itoa(u.total))
u.activeDigits = len(strconv.Itoa(u.concurrent))
concurrent := int(*service.Spec.Mode.ReplicatedJob.MaxConcurrent)
total := int(*service.Spec.Mode.ReplicatedJob.TotalCompletions)
return u
return &replicatedJobProgressUpdater{
progressOut: progressOut,
concurrent: concurrent,
total: total,
jobIteration: service.JobStatus.JobIteration.Index,
progressDigits: len(strconv.Itoa(total)),
activeDigits: len(strconv.Itoa(concurrent)),
}
}
// update writes out the progress of the replicated job.