Exemplo n.º 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU()) // use all available cpu cores

	// create a new bar and prepend the task progress to the bar and fanout into 1k go routines
	count := 1000
	bar := uiprogress.AddBar(count).AppendCompleted().PrependElapsed()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return fmt.Sprintf("Task (%d/%d)", b.Current(), count)
	})

	uiprogress.Start()
	var wg sync.WaitGroup

	// fanout into 1k go routines
	for i := 0; i < count; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			time.Sleep(time.Millisecond * time.Duration(rand.Intn(500)))
			bar.Incr()
		}()
	}
	time.Sleep(time.Second) // wait for a second for all the go routines to finish
	wg.Wait()
	uiprogress.Stop()
}
Exemplo n.º 2
0
// Save method persist (save or update) the chain on the disk
func (c *Chain) Save() {
	var cn = c.collection
	if c.collection == "" {
		cn = timeName()
		c.collection = cn
	}

	sess, coll := model.Connect(cn)
	defer sess.Close()

	ks := c.Keys()
	sort.Strings(ks)

	var wg sync.WaitGroup
	var workForce = 5
	ch := make(chan model.NewNodeInfo, workForce)

	for i := 0; i < workForce; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			var ni model.NewNodeInfo
			var more bool

			for {
				ni, more = <-ch
				if more {
					model.NewNode(ni).Save(coll)
				} else {
					return
				}
			}
		}()
	}

	count := len(ks)
	bar := uiprogress.AddBar(count)
	bar.AppendCompleted()
	bar.PrependElapsed()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return fmt.Sprintf("Node (%d/%d)", b.Current(), count)
	})

	uiprogress.Start()
	for _, x := range ks {
		ch <- model.NewNodeInfo{x, c.chain[x]}

		bar.Incr()
	}

	uiprogress.Stop()
	close(ch)
	wg.Wait()
}
Exemplo n.º 3
0
func performDeploy(args []string) error {
	if len(args) != 1 {
		return errors.New("deploy takes only 1 argument - Marathon's application definition file")
	}
	path := args[0]
	renderedConfig, err := appconfig.Render(environment, path)
	if dryRun {
		fmt.Println("Rendered app specification")
		fmt.Println(renderedConfig)
		return err
	}

	var configMap map[string]interface{}
	util.JsonDecode(renderedConfig, &configMap)
	appName := configMap["id"].(string)

	fmt.Println("Deploying " + appName + " from " + path)
	deployment, err := marathon.Deploy(appName, renderedConfig, force)
	if err != nil {
		return err
	}

	// Do fancy UI updates on the screen
	uiprogress.Start()
	defer uiprogress.Stop()
	bar := uiprogress.AddBar(timeoutInSeconds + 1)
	bar.AppendCompleted()
	bar.PrependElapsed()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return appName + " deploying"
	})

	for bar.Incr() {
		time.Sleep(time.Millisecond * 1000)
		if bar.Current()%15 == 0 { // check the deployment stauts only every 15 seconds
			stillDeploying, err := marathon.IsStillDeploying(deployment)
			if err != nil {
				return err
			}
			if !stillDeploying {
				bar.Set(timeoutInSeconds)
				time.Sleep(time.Millisecond * 20) // wait for a few ms to refresh the output
				fmt.Println("Deployment completed")
				return nil
			}
		}
	}

	return errors.New("[ERROR] App deployment timed out. Check Marathon UI for more details")
}
Exemplo n.º 4
0
					downloadChan <- hit.LargeImageURL
				}
			}
		case *pbapi.ImageDetailsResponse:
			for _, hit := range realResult.Hits {
				switch arguments.size {
				case sm:
					downloadChan <- hit.WebFormatURL
				case xs:
					downloadChan <- hit.PreviewURL
				}
			}
		}

		wg.Wait()
		uiprogress.Stop()
		time.Sleep(time.Second)
	},
}

func validateSizeArgument() {
	switch arguments.size {
	case og:
		fallthrough
	case lg:
		fallthrough
	case md:
		if arguments.request.ResponseGroup != pbapi.ResponseGroupHighResolution {
			log.Fatalf("need %s response group setting to get this image size", pbapi.ResponseGroupHighResolution)
		}
	case sm:
Exemplo n.º 5
0
func main() {
	writeConfig := flag.Bool("write-config", false, "write config to project folder")
	readConfig := flag.Bool("read-config", true, "use project config")
	genLove := flag.Bool("L", false, "generate .love")
	genOSX := flag.Bool("O", false, "generate mac app")
	genWin := flag.Bool("W", false, "generate windows app")
	//uploadToItch := flag.Bool("itch", false, "upload releases to itch")
	var folder string
	flag.StringVar(&folder, "folder", ".", "project folder")
	var projectName string
	flag.StringVar(&projectName, "name", "project", "project name")
	flag.Parse()
	folder, err := filepath.Abs(folder)
	if err != nil {
		panic(err)
	}
	if !pathExists(filepath.Join(folder, "main.lua")) {
		fmt.Println("[!] didn't find main.lua")
		fmt.Println("    in", folder)
		fmt.Println("    aborting!")
		return
	}
	fmt.Println("wiping releases folder")
	os.RemoveAll(filepath.Join(folder, "releases"))
	ensureExists(filepath.Join(folder, "releases"))
	ensureExists(filepath.Join(folder, "release-downloads"))
	options := Options{path: folder, ProjectName: projectName}
	didReadConfig := false
	if *readConfig {
		if !pathExists(filepath.Join(folder, "love-release-go.json")) {
			fmt.Println("didnt find love-release-go.json")
		} else {
			options.readConfig()
			didReadConfig = true
			fmt.Println("reading config from file... ignoring flags")
		}
	}
	if !didReadConfig {
		options.Build.Love = *genLove
		options.Build.OSX = *genOSX
		options.Build.Win = *genWin
	}
	options.fixIntegrity()
	fmt.Println(options)
	if *writeConfig {
		options.writeConfig()
	}

	var wg sync.WaitGroup

	wg.Add(3)
	uiprogress.Start()

	go buildLove(&options, &wg)
	go buildWindows(&options, &wg)
	go buildOSX(&options, &wg)
	wg.Wait()

	time.Sleep(time.Millisecond * 100)
	uiprogress.Stop()

	close(log)

	{
		i := 0
		for s := range log {
			if i == 0 {
				fmt.Println("\nWarnings:")
			}
			fmt.Println("-", s)
			i++
		}
	}

}