Skip to content

Commit

Permalink
Merge pull request #36 from hathora/idle-timeout-bug-2
Browse files Browse the repository at this point in the history
Updating idle timeout logic
  • Loading branch information
msaxon committed Jun 28, 2024
2 parents 4a7e2a5 + a1893f6 commit 8ae73a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions internal/commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var Deploy = &cli.Command{
return fmt.Errorf("unable to retrieve latest deployment: %w", err)
}

deploy.Merge(res.DeploymentV2)
deploy.Merge(res.DeploymentV2, cmd.IsSet(idleTimeoutFlag.Name))
}

if err := deploy.Validate(); err != nil {
Expand Down Expand Up @@ -108,12 +108,12 @@ func (c *DeployConfig) Load(cmd *cli.Command) error {
return nil
}

func (c *DeployConfig) Merge(latest *shared.DeploymentV2) {
func (c *DeployConfig) Merge(latest *shared.DeploymentV2, isIdleTimeoutDefault bool) {
if latest == nil {
return
}

if c.IdleTimeoutEnabled == nil {
if !isIdleTimeoutDefault {
c.IdleTimeoutEnabled = &latest.IdleTimeoutEnabled
}

Expand Down
10 changes: 9 additions & 1 deletion internal/commands/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ var (
cli.EnvVar(deploymentEnvVar("IDLE_TIMEOUT_ENABLED")),
altsrc.ConfigFile(configFlag.Name, "deployment.idle-timeout-enabled"),
),
Value: false,
Usage: "whether to shut down processes that have had no new connections or rooms for five minutes",
Persistent: true,
Category: "Deployment:",
Expand Down Expand Up @@ -401,10 +400,19 @@ func (c *CreateDeploymentConfig) Load(cmd *cli.Command) error {

c.DeploymentConfig = deployment
c.BuildID = int(cmd.Int(buildIDFlag.Name))

// Value of the idleTimeoutFlag by priority, high to low
// Passed in as an argument
// From latest deployment config (if from-latest is true)
// Default true
if cmd.IsSet(idleTimeoutFlag.Name) {
idleTimeoutEnabled := cmd.Bool(idleTimeoutFlag.Name)
c.IdleTimeoutEnabled = &idleTimeoutEnabled
} else {
idleTimeoutEnabled := true
c.IdleTimeoutEnabled = &idleTimeoutEnabled
}

c.RoomsPerProcess = int(cmd.Int(roomsPerProcessFlag.Name))
c.TransportType = shared.TransportType(cmd.String(transportTypeFlag.Name))
c.ContainerPort = int(cmd.Int(containerPortFlag.Name))
Expand Down

0 comments on commit 8ae73a5

Please sign in to comment.