* Parallelise Bulk Import.

* Set worker count through command line flag.
Этот коммит содержится в:
George Goldberg
2017-04-28 17:54:04 +01:00
коммит произвёл GitHub
родитель 36a15925dc
Коммит 302ec17bee
3 изменённых файлов: 77 добавлений и 7 удалений

Просмотреть файл

@@ -35,6 +35,7 @@ var bulkImportCmd = &cobra.Command{
func init() {
bulkImportCmd.Flags().Bool("apply", false, "Save the import data to the database. Use with caution - this cannot be reverted.")
bulkImportCmd.Flags().Bool("validate", false, "Validate the import data without making any changes to the system.")
bulkImportCmd.Flags().Int("workers", 2, "How many workers to run whilst doing the import.")
importCmd.AddCommand(
bulkImportCmd,
@@ -87,6 +88,11 @@ func bulkImportCmdF(cmd *cobra.Command, args []string) error {
return errors.New("Validate flag error")
}
workers, err := cmd.Flags().GetInt("workers")
if err != nil {
return errors.New("Workers flag error")
}
if len(args) != 1 {
return errors.New("Incorrect number of arguments.")
}
@@ -110,7 +116,7 @@ func bulkImportCmdF(cmd *cobra.Command, args []string) error {
CommandPrettyPrintln("")
if err, lineNumber := app.BulkImport(fileReader, !apply); err != nil {
if err, lineNumber := app.BulkImport(fileReader, !apply, workers); err != nil {
CommandPrettyPrintln(err.Error())
if lineNumber != 0 {
CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))