Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into advisor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mierdin authored Feb 5, 2019
2 parents e3bb82e + c1f1c8d commit 9f4e7b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## In development

- Fixed GC goroutine; make GC interval configurable [#63](https://github.com/nre-learning/syringe/pull/63/files)

## 0.2.0 - January 24, 2019

- Simplified authentication by using consistent credentials, statically [#40](https://github.com/nre-learning/syringe/pull/40)
- Serve lab guide directly from lesson definition API [#41](https://github.com/nre-learning/syringe/pull/41)
- Simplify and improve safety of in-memory state model [#42](https://github.com/nre-learning/syringe/pull/42)
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type SyringeConfig struct {
HealthCheckInterval int
TSDBExportInterval int
TSDBEnabled bool
GCInterval int

LessonRepoRemote string
LessonRepoBranch string
Expand Down Expand Up @@ -94,6 +95,13 @@ func LoadConfigVars() (*SyringeConfig, error) {
config.LessonRepoDir = dir
}

gc, err := strconv.Atoi(os.Getenv("SYRINGE_GC_INTERVAL"))
if gc == 0 || err != nil {
config.GCInterval = 30
} else {
config.GCInterval = gc
}

return &config, nil

}
14 changes: 8 additions & 6 deletions scheduler/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (ls *LessonScheduler) createNamespace(req *LessonScheduleRequest) (*corev1.
Labels: map[string]string{
"lessonId": fmt.Sprintf("%d", req.LessonDef.LessonId),
"syringeManaged": "yes",
"name": nsName,
"name": nsName,
"syringeTier": ls.SyringeConfig.Tier,
"lastAccessed": strconv.Itoa(int(time.Now().Unix())),
"created": strconv.Itoa(int(time.Now().Unix())),
Expand Down Expand Up @@ -185,7 +185,8 @@ func (ls *LessonScheduler) purgeOldLessons() ([]string, error) {
panic(err)
}
lastAccessed := time.Unix(i, 0)
if time.Since(lastAccessed) < 30*time.Minute {

if time.Since(lastAccessed) < time.Duration(ls.SyringeConfig.GCInterval)*time.Minute {
continue
}

Expand All @@ -205,14 +206,15 @@ func (ls *LessonScheduler) purgeOldLessons() ([]string, error) {
return []string{}, nil
}

log.Warnf("Garbage-collecting %d old lessons", len(oldNameSpaces))
log.Infof("Garbage-collecting %d old lessons", len(oldNameSpaces))
log.Debug(oldNameSpaces)
var wg sync.WaitGroup
wg.Add(len(oldNameSpaces))
for n := range oldNameSpaces {
go func() {
go func(ns string) {
defer wg.Done()
ls.deleteNamespace(oldNameSpaces[n])
}()
ls.deleteNamespace(ns)
}(oldNameSpaces[n])
}
wg.Wait()
log.Infof("Finished garbage-collecting %d old lessons", len(oldNameSpaces))
Expand Down

0 comments on commit 9f4e7b0

Please sign in to comment.