-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move workers to hidden, add clean command and make dry-run via cli work
- Loading branch information
Showing
8 changed files
with
103 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/l3uddz/crop/config" | ||
"github.com/l3uddz/crop/uploader" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
"github.com/yale8848/gorpool" | ||
) | ||
|
||
var cleanCmd = &cobra.Command{ | ||
Use: "clean [UPLOADER]", | ||
Short: "Perform uploader clean", | ||
Long: `This command can be used to trigger an uploader clean.`, | ||
|
||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// init core | ||
initCore(true) | ||
|
||
// iterate uploader's | ||
for uploaderName, uploaderConfig := range config.Config.Uploader { | ||
// skip disabled uploader(s) | ||
if !uploaderConfig.Enabled { | ||
log.WithField("uploader", uploaderName).Trace("Skipping disabled uploader") | ||
continue | ||
} | ||
|
||
log := log.WithField("uploader", uploaderName) | ||
|
||
// create uploader | ||
upload, err := uploader.New(config.Config, &uploaderConfig, uploaderName) | ||
if err != nil { | ||
log.WithField("uploader", uploaderName).WithError(err). | ||
Error("Failed initializing uploader, skipping...") | ||
continue | ||
} | ||
|
||
log.Info("Clean commencing...") | ||
|
||
// perform upload | ||
if err := performClean(upload); err != nil { | ||
upload.Log.WithError(err).Error("Error occurred while running clean, skipping...") | ||
continue | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(cleanCmd) | ||
} | ||
|
||
func performClean(u *uploader.Uploader) error { | ||
u.Log.Info("Running cleans...") | ||
|
||
/* Cleans */ | ||
if u.Config.Hidden.Enabled { | ||
// set worker count | ||
workers := u.Config.Hidden.Workers | ||
if workers == 0 { | ||
workers = 8 | ||
} | ||
|
||
// create worker pool | ||
gp := gorpool.NewPool(workers, 0). | ||
Start(). | ||
EnableWaitForAll(true) | ||
|
||
// queue clean tasks | ||
err := u.PerformCleans(gp) | ||
if err != nil { | ||
return errors.Wrap(err, "failed clearing remotes") | ||
} | ||
} | ||
|
||
u.Log.Info("Finished cleans!") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters