Skip to content

Commit

Permalink
Merge pull request #91 from seatgeek/safer-cleanup
Browse files Browse the repository at this point in the history
refactor: call system gc once instead of after each job cleanup iteration
  • Loading branch information
josegonzalez authored Sep 30, 2022
2 parents 97be0b8 + 57b368b commit a160e91
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions command/namespace/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func GC(c *cli.Context, logger *log.Logger) error {
return err
}

if len(jobs) == 0 {
continue
}

if c.Bool("dry") {
logger.Infof("Skipping deletion of %d jobs in region/namespace %s/%s because dry flag was provided", len(jobs), region, namespace.Name)
continue
Expand All @@ -75,16 +79,22 @@ func GC(c *cli.Context, logger *log.Logger) error {
}
logger.Infof("Job '%s' in region/namespace '%s/%s' successfully deleted", job.ID, region, namespace.Name)
}
}
}

if err := nomadClient.System().GarbageCollect(); err != nil {
return fmt.Errorf("error running garbage collection: %w", err)
}
if !c.Bool("dry") {
logger.Infof("executing garbage collection")
if err := nomadClient.System().GarbageCollect(); err != nil {
return fmt.Errorf("error running garbage collection: %w", err)
}

if err := nomadClient.System().ReconcileSummaries(); err != nil {
return fmt.Errorf("error reconciling summaries: %w", err)
}
logger.Infof("executing summary reconciliation")
if err := nomadClient.System().ReconcileSummaries(); err != nil {
return fmt.Errorf("error reconciling summaries: %w", err)
}
}

for _, namespace := range deletableNamespaces {
if c.Bool("dry") {
logger.Infof("Skipping deletion of namespace %s because dry flag was provided", namespace.Name)
continue
Expand Down

0 comments on commit a160e91

Please sign in to comment.