Skip to content

Commit

Permalink
change(cmd): show how long it took from start to finish for: clean, m…
Browse files Browse the repository at this point in the history
…anual, sync and upload commands
  • Loading branch information
l3uddz committed May 17, 2020
1 parent 4790ff6 commit f2606ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/clean.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cmd

import (
"github.com/dustin/go-humanize"
"github.com/l3uddz/crop/config"
"github.com/l3uddz/crop/uploader"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/yale8848/gorpool"
"strings"
"time"
)

var cleanCmd = &cobra.Command{
Expand All @@ -19,6 +21,8 @@ var cleanCmd = &cobra.Command{
initCore(true)

// iterate uploader's
started := time.Now().UTC()

for _, uploaderConfig := range config.Config.Uploader {
log := log.WithField("uploader", uploaderConfig.Name)

Expand Down Expand Up @@ -49,6 +53,8 @@ var cleanCmd = &cobra.Command{
continue
}
}

log.Infof("Finished in: %v", humanize.RelTime(started, time.Now().UTC(), "", ""))
},
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -109,6 +110,7 @@ var manualCmd = &cobra.Command{
}

// create syncer
started := time.Now().UTC()
sync, err := syncer.New(&cfg, &syncerConfig, syncerConfig.Name, 1)
if err != nil {
log.WithError(err).Fatal("Failed initializing syncer, skipping...")
Expand Down Expand Up @@ -147,7 +149,7 @@ var manualCmd = &cobra.Command{
sync.Log.WithError(err).Fatal("Error occurred while running syncer, skipping...")
}

log.Info("Finished!")
log.Infof("Finished in: %v", humanize.RelTime(started, time.Now().UTC(), "", ""))
},
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
"strings"
"sync"
"time"
)

var (
Expand Down Expand Up @@ -40,6 +41,8 @@ var syncCmd = &cobra.Command{
}

// iterate syncer's
started := time.Now().UTC()

for _, syncerConfig := range config.Config.Syncer {
syncerConfig := syncerConfig

Expand Down Expand Up @@ -99,6 +102,8 @@ var syncCmd = &cobra.Command{
log.Info("Waiting for syncer(s) to finish")
close(jobs)
wg.Wait()

log.Infof("Finished in: %v", humanize.RelTime(started, time.Now().UTC(), "", ""))
},
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"strings"
"time"
)

var (
Expand All @@ -28,6 +29,8 @@ var uploadCmd = &cobra.Command{
defer cache.Close()

// iterate uploader's
started := time.Now().UTC()

for _, uploaderConfig := range config.Config.Uploader {
log := log.WithField("uploader", uploaderConfig.Name)

Expand Down Expand Up @@ -103,6 +106,8 @@ var uploadCmd = &cobra.Command{
continue
}
}

log.Infof("Finished in: %v", humanize.RelTime(started, time.Now().UTC(), "", ""))
},
}

Expand Down

0 comments on commit f2606ef

Please sign in to comment.