mirror of
https://github.com/nxshock/gwp.git
synced 2024-11-27 03:31:02 +05:00
Add option to show progress
This commit is contained in:
parent
cda1b68900
commit
7c3de6635f
@ -29,7 +29,8 @@ func f(i int) error {
|
||||
func main() {
|
||||
|
||||
worker := gwp.New(4) // Create pool with specified number of workers
|
||||
worker.EstimateCount = 100 // Set estimate jobs count count to show progress
|
||||
worker.ShowProgress = true // Enable progress indicator
|
||||
worker.EstimateCount = 100 // Set total number on jobs to calculate ETA
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
n := i
|
||||
|
6
gwp.go
6
gwp.go
@ -14,7 +14,9 @@ type WorkerPool struct {
|
||||
resultChan chan error
|
||||
stopChan chan struct{}
|
||||
wg sync.WaitGroup
|
||||
|
||||
EstimateCount int
|
||||
ShowProgress bool
|
||||
|
||||
processedCount int // processed jobs count
|
||||
errorCount int // processed jobs count that returned error
|
||||
@ -80,7 +82,7 @@ func New(threadCount int) *WorkerPool {
|
||||
}
|
||||
|
||||
func (workerPool *WorkerPool) printProgress() {
|
||||
if workerPool.EstimateCount == 0 {
|
||||
if !workerPool.ShowProgress {
|
||||
return
|
||||
}
|
||||
|
||||
@ -92,7 +94,7 @@ func (workerPool *WorkerPool) printProgress() {
|
||||
fmt.Fprintf(os.Stderr, " Errors: %d (%.1f%%)",
|
||||
workerPool.errorCount, float64(workerPool.errorCount*100)/float64(workerPool.EstimateCount))
|
||||
}
|
||||
if workerPool.currentSpeed > 0 {
|
||||
if workerPool.EstimateCount > 0 && workerPool.currentSpeed > 0 {
|
||||
fmt.Fprintf(os.Stderr, " ETA: %s at %.2f rps",
|
||||
time.Second*time.Duration(float64(workerPool.EstimateCount-workerPool.processedCount)/workerPool.currentSpeed), workerPool.currentSpeed)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user