-
Notifications
You must be signed in to change notification settings - Fork 1k
Made command timeouts configurable #1028
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ import ( | |
"bytes" | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
@@ -196,12 +198,31 @@ func runFromRepoDir(ctx context.Context, repo vcs.Repo, timeout time.Duration, c | |
return c.combinedOutput(ctx) | ||
} | ||
|
||
func getenvDuration(key string, def time.Duration) time.Duration { | ||
seconds, err := strconv.Atoi(os.Getenv(key)) | ||
|
||
if err != nil { | ||
return def | ||
} | ||
|
||
return time.Duration(seconds) * time.Second | ||
} | ||
|
||
const ( | ||
// envExpensiveCmdTimeout is the environment variable to read for the | ||
// expensiveCmdTimeout default, in seconds. | ||
envExpensiveCmdTimeout = "DEP_EXPENSIVE_CMD_TIMEOUT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently dep isn't relying upon any environment variables (other than in tests). I'm not sure if we want to start doing that, instead of continuing to use flags? I'll let @sdboyer have the final say on that though. If we do stick with environment variables, they should be documented in the help text too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually felt uncomfortable adding those environment variables where no other were currently used. I went with those anyway because:
Perhaps a configuration file of some sort (like That being said, when in Rome, I'll do as the romans do so feel free to confirm or reject my decisions and I'll happily update my PR !
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, I hadn't thought of that! Personally I'm fine with the environment variable. Let's move forward with that for now. 👍 The next step is to get some tests that exercise changing the timeout. I don't know how easy/hard that will end up being so if you find yourself going down a rabbit hole, post back here and we can think about it more! |
||
// envDefaultCmdTimeout is the environment variable to read for the | ||
// envDefaultCmdTimeout default, in seconds. | ||
envDefaultCmdTimeout = "DEP_DEFAULT_CMD_TIMEOUT" | ||
) | ||
|
||
var ( | ||
// expensiveCmdTimeout is meant to be used in a command that is expensive | ||
// in terms of computation and we know it will take long or one that uses | ||
// the network, such as clones, updates, .... | ||
expensiveCmdTimeout = 2 * time.Minute | ||
expensiveCmdTimeout = getenvDuration(envExpensiveCmdTimeout, 2*time.Minute) | ||
// defaultCmdTimeout is just an umbrella value for all other commands that | ||
// should not take much. | ||
defaultCmdTimeout = 10 * time.Second | ||
defaultCmdTimeout = getenvDuration(envDefaultCmdTimeout, 10*time.Second) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives no indication to the user when their environment variable is set but isn't convertible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. It might be confusing.
I don't mind making this more user-friendly. However I will put that on hold until we have consensus that the environment variables are indeed the way to go.