aboutsummaryrefslogtreecommitdiff
path: root/tasks/helpers.go
blob: b99a977cec2d6bfc90398a5359be64bcf1eb8659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
package tasks

import "time"

func calculateProgress(current, total int, startTime time.Time) (progress float64, eta time.Duration) {
	progress = float64(current) / float64(total) * 100
	elapsed := time.Since(startTime)
	avgTimePerItem := elapsed / time.Duration(current)
	remaining := total - current
	eta = avgTimePerItem * time.Duration(remaining)
	return progress, eta.Round(time.Second)
}