Skip to content

Commit

Permalink
cli: --no-wait flag for create deployment
Browse files Browse the repository at this point in the history
fixes: #287
  • Loading branch information
aastein authored Jul 16, 2018
1 parent 51184e3 commit a7c14ac
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion _integration/cmp/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func deployCreate(key vars.Ref, daddr vars.Ref) gestalt.Component {

return g.Group("deploy-create").
Run(
akash("create", "deployment", "create", "{{deployment-path}}", "-k", key.Name()).
akash("create", "deployment", "create", "{{deployment-path}}", "-k", key.Name(), "--no-wait").
FN(g.Capture(daddr.Name())).
WithMeta(g.Export(daddr.Name()))).
Run(g.Retry(5).Run(check)).
Expand Down
2 changes: 1 addition & 1 deletion cmd/akash/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
KeyType = "ed25519"

// market commands
FlagWait = "wait"
FlagNoWait = "no-wait"

// todo: interactive.
Password = "0123456789"
Expand Down
70 changes: 35 additions & 35 deletions cmd/akash/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,43 +101,43 @@ func createDeployment(session session.Session, cmd *cobra.Command, args []string

fmt.Println(X(address))

if session.Wait() {
fmt.Printf("Waiting...\n")
expected := len(groups)
handler := marketplace.NewBuilder().
OnTxCreateFulfillment(func(tx *types.TxCreateFulfillment) {
if bytes.Equal(tx.Deployment, address) {
fmt.Printf("Group %v/%v Fulfillment: %v [price=%v]\n", tx.Group, len(groups), tx.FulfillmentID, tx.Price)
if session.NoWait() {
return nil
}

fmt.Printf("Waiting...\n")
expected := len(groups)
handler := marketplace.NewBuilder().
OnTxCreateFulfillment(func(tx *types.TxCreateFulfillment) {
if bytes.Equal(tx.Deployment, address) {
fmt.Printf("Group %v/%v Fulfillment: %v [price=%v]\n", tx.Group, len(groups), tx.FulfillmentID, tx.Price)
}
}).
OnTxCreateLease(func(tx *types.TxCreateLease) {
if bytes.Equal(tx.Deployment, address) {
fmt.Printf("Group %v/%v Lease: %v [price=%v]\n", tx.Group, len(groups), tx.LeaseID, tx.Price)
// get lease provider
prov, err := session.QueryClient().Provider(session.Ctx(), tx.Provider)
if err != nil {
fmt.Printf("ERROR: %v", err)
}
}).
OnTxCreateLease(func(tx *types.TxCreateLease) {
if bytes.Equal(tx.Deployment, address) {
fmt.Printf("Group %v/%v Lease: %v [price=%v]\n", tx.Group, len(groups), tx.LeaseID, tx.Price)
// get lease provider
prov, err := session.QueryClient().Provider(session.Ctx(), tx.Provider)
if err != nil {
fmt.Printf("ERROR: %v", err)
}

// send manifest over http to provider uri
fmt.Printf("Sending manifest to %v...\n", prov.HostURI)
err = http.SendManifest(mani, txclient.Signer(), prov, tx.Deployment)
if err != nil {
fmt.Printf("ERROR: %v", err)
}
expected--
}
if expected == 0 {
os.Exit(0)
}
}).Create()

return common.RunForever(func(ctx context.Context) error {
return common.MonitorMarketplace(ctx, session.Log(), session.Client(), handler)
})
}

return nil
// send manifest over http to provider uri
fmt.Printf("Sending manifest to %v...\n", prov.HostURI)
err = http.SendManifest(mani, txclient.Signer(), prov, tx.Deployment)
if err != nil {
fmt.Printf("ERROR: %v", err)
}
expected--
}
if expected == 0 {
os.Exit(0)
}
}).Create()

return common.RunForever(func(ctx context.Context) error {
return common.MonitorMarketplace(ctx, session.Log(), session.Client(), handler)
})
}

func closeDeploymentCommand() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/akash/session/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func AddFlagKeyType(cmd *cobra.Command, flags *pflag.FlagSet) {
}

func AddFlagWait(cmd *cobra.Command, flags *pflag.FlagSet) {
flags.BoolP(constants.FlagWait, "w", false, "Wait for market confirmation")
flags.Bool(constants.FlagNoWait, false, "Do not wait for lease creation")
}

func parseFlagKeyType(flags *pflag.FlagSet) (keys.CryptoAlgo, error) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/akash/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Session interface {
Log() log.Logger
Signer() (txutil.Signer, keys.Info, error)
Ctx() context.Context
Wait() bool
NoWait() bool
}

type cmdRunner func(cmd *cobra.Command, args []string) error
Expand Down Expand Up @@ -230,8 +230,8 @@ func (ctx *session) Nonce() (uint64, error) {
return txclient.Nonce()
}

func (ctx *session) Wait() bool {
val, _ := ctx.cmd.Flags().GetBool(constants.FlagWait)
func (ctx *session) NoWait() bool {
val, _ := ctx.cmd.Flags().GetBool(constants.FlagNoWait)
return val
}

Expand Down

0 comments on commit a7c14ac

Please sign in to comment.