Skip to content

Commit

Permalink
More detailed progress status
Browse files Browse the repository at this point in the history
  • Loading branch information
mingrammer authored and stzminjae committed Feb 20, 2019
1 parent c098ab4 commit 5dee279
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions toolkit/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ func (t *Truncator) truncate(table string) error {
totalSegments = calc.Min(totalSegments, maxTotalSegments)
if totalSegments == 0 {
cfmt.Warningf("Table '%s' has no items.\n", table)
return nil
}

// Delete all keys
cfmt.Successf("[%d/%d] Truncating the table '%s'...\n", 0, totalSegments, table)
errc := make(chan error, 1)
wg := sync.WaitGroup{}
wg.Add(int(totalSegments))
for i := int64(0); i < totalSegments; i++ {
go func(segment int64) {
defer wg.Done()
cfmt.Infof("[%d/%d] Truncating the table '%s'...\n", segment+1, totalSegments, table)
cfmt.Infof("[%d/%d] Deleting the %d segment of table '%s'...\n", segment+1, totalSegments, segment, table)
scanned, err := t.client.Scan(&dynamodb.ScanInput{
TableName: aws.String(table),
AttributesToGet: keys,
Expand All @@ -116,11 +118,12 @@ func (t *Truncator) truncate(table string) error {
if err != nil {
errc <- err
}
cfmt.Successf("[%d/%d] Table '%s' was truncated successfully.\n", segment+1, totalSegments, table)
cfmt.Successf("[%d/%d] The %d segment of table '%s' was deleted.\n", segment+1, totalSegments, segment, table)
}(i)
}
go func() {
wg.Wait()
cfmt.Successf("[%d/%d] Table '%s' was truncated successfully.\n", totalSegments, totalSegments, table)
close(errc)
}()
return <-errc
Expand Down

0 comments on commit 5dee279

Please sign in to comment.