Skip to content

Commit

Permalink
MINOR: add option to allow delay starting runtime
Browse files Browse the repository at this point in the history
added AllowDelayedStartMax and AllowDelayedStartTick
to check allow slower starting of HAProxy, useful on limited machines.
these can be accessed with runtimeOptions.AllowDelayedStart(max, tick)
  • Loading branch information
oktalz committed Feb 27, 2024
1 parent ce9af65 commit 9523e55
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
37 changes: 37 additions & 0 deletions runtime/options/allow-delayed-start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2022 HAProxy Technologies
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import "time"

type allowDelayedStart struct {
allowDelayedStartMax time.Duration
allowDelayedStartTick time.Duration
}

func (d allowDelayedStart) Set(o *RuntimeOptions) error {
o.AllowDelayedStartMax = &d.allowDelayedStartMax
o.AllowDelayedStartTick = &d.allowDelayedStartTick
return nil
}

func AllowDelayedStart(allowDelayedStartMax, allowDelayedStartTick time.Duration) RuntimeOption {
return allowDelayedStart{
allowDelayedStartMax: allowDelayedStartMax,
allowDelayedStartTick: allowDelayedStartTick,
}
}
4 changes: 4 additions & 0 deletions runtime/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ limitations under the License.

package options

import "time"

type RuntimeOptions struct {
MapsDir *string
MasterSocketData *masterSocketData
Sockets map[int]string
DoNotCheckRuntimeOnInit bool
AllowDelayedStartMax *time.Duration
AllowDelayedStartTick *time.Duration
}

type RuntimeOption interface {
Expand Down
20 changes: 17 additions & 3 deletions runtime/runtime_single_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,23 @@ func (s *SingleRuntime) Init(ctx context.Context, socketPath string, worker int,
s.process = process
go s.handleIncomingJobs(ctx)
if !runtimeOptions.DoNotCheckRuntimeOnInit {
// check if we have a valid socket
if _, err := s.ExecuteRaw("help"); err != nil {
return err
if runtimeOptions.AllowDelayedStartMax != nil {
now := time.Now()
var err error
for {
if _, err = s.ExecuteRaw("help"); err == nil {
break
}
time.Sleep(*runtimeOptions.AllowDelayedStartTick)
if time.Since(now) > *runtimeOptions.AllowDelayedStartMax {
return fmt.Errorf("cannot connect to runtime API %s within %s: %w", socketPath, *runtimeOptions.AllowDelayedStartMax, err)
}
}
} else {
// check if we have a valid socket
if _, err := s.ExecuteRaw("help"); err != nil {
return err
}
}
}
return nil
Expand Down

0 comments on commit 9523e55

Please sign in to comment.