@@ -2,25 +2,28 @@ package fleet
22
33import (
44 "fmt"
5+ "io"
56 "strings"
67 "sync"
78 "time"
89
910 "github.com/coreos/fleet/job"
1011 "github.com/coreos/fleet/schema"
1112 "github.com/coreos/fleet/unit"
13+
14+ "github.com/deis/deis/pkg/prettyprint"
1215)
1316
1417// Create schedules unit files for the given components.
1518func (c * FleetClient ) Create (
16- targets []string , wg * sync.WaitGroup , outchan chan string , errchan chan error ) {
19+ targets []string , wg * sync.WaitGroup , out , ew io. Writer ) {
1720
1821 units := make ([]* schema.Unit , len (targets ))
1922
2023 for i , target := range targets {
2124 unitName , unitFile , err := c .createUnitFile (target )
2225 if err != nil {
23- errchan <- err
26+ fmt . Fprintf ( ew , "Error creating: %s \n " , err )
2427 return
2528 }
2629 units [i ] = & schema.Unit {
@@ -31,28 +34,29 @@ func (c *FleetClient) Create(
3134
3235 for _ , unit := range units {
3336 wg .Add (1 )
34- go doCreate (c , unit , wg , outchan , errchan )
37+ go doCreate (c , unit , wg , out , ew )
3538 }
3639}
3740
38- func doCreate (c * FleetClient , unit * schema.Unit , wg * sync.WaitGroup , outchan chan string , errchan chan error ) {
41+ func doCreate (c * FleetClient , unit * schema.Unit , wg * sync.WaitGroup , out , ew io. Writer ) {
3942 defer wg .Done ()
4043
4144 // create unit definition
4245 if err := c .Fleet .CreateUnit (unit ); err != nil {
4346 // ignore units that already exist
4447 if err .Error () != "job already exists" {
45- errchan <- err
48+ fmt . Fprintln ( ew , err . Error ())
4649 return
4750 }
4851 }
4952
5053 desiredState := string (job .JobStateLoaded )
51- out := fmt .Sprintf ("\033 [0;33m%v:\033 [0m loaded \r " , unit .Name )
54+ tpl := prettyprint .Colorize ("{{.Yellow}}%v:{{.Default}} loaded" )
55+ msg := fmt .Sprintf (tpl , unit .Name )
5256
5357 // schedule the unit
5458 if err := c .Fleet .SetUnitTargetState (unit .Name , desiredState ); err != nil {
55- errchan <- err
59+ fmt . Fprintln ( ew , err )
5660 return
5761 }
5862
@@ -62,7 +66,7 @@ outerLoop:
6266 time .Sleep (250 * time .Millisecond )
6367 unitStates , err := c .Fleet .UnitStates ()
6468 if err != nil {
65- errchan <- err
69+ fmt . Fprintln ( ew , err )
6670 }
6771 for _ , us := range unitStates {
6872 if strings .HasPrefix (us .Name , unit .Name ) {
@@ -71,7 +75,7 @@ outerLoop:
7175 }
7276 }
7377
74- outchan <- out
78+ fmt . Fprintln ( out , msg )
7579}
7680
7781func (c * FleetClient ) createUnitFile (target string ) (unitName string , uf * unit.UnitFile , err error ) {
0 commit comments