Skip to content

Commit

Permalink
feat: Add ability to perform periodic cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
achetronic committed Oct 21, 2024
1 parent 8d518d0 commit c3612c7
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,31 @@ import (
"log"
"os"
"os/signal"
"runtime/debug"
"syscall"
"time"

"bifrost/internal/config"
"bifrost/internal/globals"
"bifrost/internal/httpserver"
)

var (
logLevelFlag = flag.String("log-level", "info", "Verbosity level for logs")
disableTraceFlag = flag.Bool("disable-trace", true, "Disable showing traces in logs")
configFlag = flag.String("config", "bifrost.yaml", "Path to the config file")
logLevelFlag = flag.String("log-level", "info", "Verbosity level for logs")
disableTraceFlag = flag.Bool("disable-trace", true, "Disable showing traces in logs")
configFlag = flag.String("config", "bifrost.yaml", "Path to the config file")
enablePeriodicCleanupFlag = flag.Bool("enable-periodic-cleanup", false, "Enable periodic memory cleanup")
periodicCleanupDurationFlag = flag.String("periodic-cleanup-duration", "4m", "Duration for periodic memory cleanup")
)

// periodicFree is a function that runs periodically to free memory
func periodicFree(d time.Duration) {
tick := time.Tick(d)
for range tick {
debug.FreeOSMemory()
}
}

func main() {
flag.Parse()

Expand Down Expand Up @@ -62,6 +74,15 @@ func main() {
// EXECUTION FLOW RELATED
/////////////////////////////

if *enablePeriodicCleanupFlag {

periodicCleanupDuration, err := time.ParseDuration(*periodicCleanupDurationFlag)
if err != nil {
globals.Application.Logger.Fatalf(fmt.Sprintf("failed parsing periodic cleanup duration: %s", err.Error()))
}
go periodicFree(periodicCleanupDuration)
}

s := httpserver.NewHttpServer()
go s.Run(fmt.Sprintf("%s:%s", configContent.Listener.Host, configContent.Listener.Port))
defer s.Stop()
Expand Down

0 comments on commit c3612c7

Please sign in to comment.