~comcloudway/builds.sr.ht

b89f882c7e4d756ba3fb60548a59d869ae3dfc4d — Jakob Meier 9 months ago 3dd68ae master
Allow guest settle timeout to be configured

Falls back to 120seconds per default if the key isn't in the config
file.
Assumes startup-timeout is in seconds
e.g. 120 for 2 minutes
1 files changed, 17 insertions(+), 1 deletions(-)

M worker/tasks.go
M worker/tasks.go => worker/tasks.go +17 -1
@@ 100,7 100,23 @@ func (ctx *JobContext) Settle() error {
	settleTimer := prometheus.NewTimer(settleTime.WithLabelValues(ctx.Manifest.Image, arch))
	defer settleTimer.ObserveDuration()

	timeout, cancel := context.WithTimeout(ctx.Context, 120*time.Second)
	var (
		ok bool
		err error
		startupTimeout int
		startupTimeoutRaw string
	)
	// assumes the timeout is specified as an int in seconds
	// e.g. 120 for 2 minutes
	if startupTimeoutRaw, ok = config.Get("builds.sr.ht::worker", "startup-timeout"); !ok {
		// default to old hardcoded value if the key wasn't found in the config file
		startupTimeoutRaw = "120"
	}
	if startupTimeout, err = strconv.Atoi(startupTimeoutRaw); err != nil {
		return errors.New("The startup-timeout could not be read")
	}

	timeout, cancel := context.WithTimeout(ctx.Context, time.Duration(startupTimeout)*time.Second)
	defer cancel()
	done := make(chan error, 1)
	attempt := 0