Skip to content

Commit

Permalink
timeout execution interval time from env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Jul 30, 2021
1 parent eee64b9 commit 0dec078
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ type Config struct {
Address string `help:"the address to bind our web server to"`
Port int `help:"the port to bind our web server to"`

UUIDSeed int `help:"seed to use for UUID generation in a testing environment"`
UUIDSeed int `help:"seed to use for UUID generation in a testing environment"`
TimeoutTime int `help:"the amount of time to between every timeout queued"`
}

// NewMailroomConfig returns a new default configuration object
Expand Down Expand Up @@ -102,7 +103,8 @@ func NewMailroomConfig() *Config {
Address: "localhost",
Port: 8090,

UUIDSeed: 0,
UUIDSeed: 0,
TimeoutTime: 15,
}
}

Expand Down
9 changes: 4 additions & 5 deletions core/tasks/timeouts/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ import (
)

const (
timeoutLock = "sessions_timeouts"
markerGroup = "session_timeouts"
tickInterval = 15
timeoutLock = "sessions_timeouts"
markerGroup = "session_timeouts"
)

func init() {
mailroom.AddInitFunction(StartTimeoutCron)
}

// StartTimeoutCron starts our cron job of continuing timed out sessions every minute
// StartTimeoutCron starts our cron job of continuing timed out sessions every defined interval in config TimeoutTime
func StartTimeoutCron(mr *mailroom.Mailroom) error {
cron.StartCron(mr.Quit, mr.RP, timeoutLock, time.Second*tickInterval,
cron.StartCron(mr.Quit, mr.RP, timeoutLock, time.Second*time.Duration(mr.Config.TimeoutTime),
func(lockName string, lockValue string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
defer cancel()
Expand Down

0 comments on commit 0dec078

Please sign in to comment.