Skip to content

Commit

Permalink
[FEAT] add timeout to cook command and adjust command variable (#110)
Browse files Browse the repository at this point in the history
* add timeout to cook command and adjust command variable

* a few updates to fix some bugs with the new cookTimeout
  • Loading branch information
johnmckenna-snd authored Aug 12, 2024
1 parent 3311e5c commit 93d9819
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/grlx/cmd/cook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import (
"github.com/gogrlx/grlx/types"
)

var async bool
var (
async bool
cookTimeout int
)

// cmdCmd represents the cmd command
var cookCmd = &cobra.Command{
Expand Down Expand Up @@ -114,7 +117,7 @@ var cmdCook = &cobra.Command{
}
// TODO convert this to a request and get back the list of targeted sprouts
ec.Publish(fmt.Sprintf("grlx.farmer.cook.trigger.%s", jid), types.TriggerMsg{JID: jid})
timeout := time.After(30 * time.Second)
localTimeout := time.After(time.Duration(cookTimeout) * time.Second)
dripTimeout := time.After(120 * time.Second)
concurrent := 0
defer sub.Unsubscribe()
Expand All @@ -135,14 +138,14 @@ var cmdCook = &cobra.Command{
}

completionSteps[completion.SproutID] = append(completionSteps[completion.SproutID], completion.CompletedStep)
timeout = time.After(30 * time.Second)
localTimeout = time.After(time.Duration(cookTimeout) * time.Second)
case <-finished:
break waitLoop
case <-dripTimeout:
finished <- struct{}{}
break waitLoop
case <-timeout:
color.Red("Cooking timed out after 30 seconds.")
case <-localTimeout:
color.Red(fmt.Sprintf("Cooking timed out after %d seconds.", cookTimeout))
finished <- struct{}{}
break waitLoop
}
Expand Down Expand Up @@ -190,6 +193,7 @@ func init() {
cmdCook.Flags().StringVarP(&environment, "environment", "E", "", "")
cmdCook.Flags().BoolVar(&async, "async", false, "Don't print any output, just return the JID to look up results later")
cmdCook.PersistentFlags().StringVarP(&sproutTarget, "target", "T", "", "list of sprouts to target")
cmdCook.Flags().IntVar(&cookTimeout, "cook-timeout", 30, "Cancel cook execution and return after X seconds")
cmdCook.MarkPersistentFlagRequired("target")
rootCmd.AddCommand(cmdCook)
}

0 comments on commit 93d9819

Please sign in to comment.