Skip to content

Commit f16bf2a

Browse files
committed
WIP: nick.farrell 02/10/25 11:24 fedora
1 parent 234838b commit f16bf2a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

plugin/plugin.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ func (t *TargetPlugin) Scale(action sdk.ScalingAction, config map[string]string)
168168
return fmt.Errorf("failed to describe DigitalOcedroplets: %w", err)
169169
}
170170

171-
debounce("deleteOrphanedDroplets", func() {
172-
t.logger.Info("performing periodic check for orphaned droplets")
173-
deleteOrphanedDroplets(ctx, t.logger, t.client.Droplets(), t.getReadyNomadClients, template)
174-
}, time.Minute*10)
175-
176171
diff, direction := t.calculateDirection(total, action.Count)
177172

178173
switch direction {
@@ -214,6 +209,15 @@ func (t *TargetPlugin) Status(config map[string]string) (*sdk.TargetStatus, erro
214209
return nil, err
215210
}
216211

212+
// If it's been at least 10 minutes since the last check for orphaned
213+
// droplets, run one now (in a separate goroutine)
214+
go debounce("deleteOrphanedDroplets", func() {
215+
t.logger.Info("performing periodic check for orphaned droplets")
216+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
217+
defer cancel()
218+
deleteOrphanedDroplets(ctx, t.logger, t.client.Droplets(), t.getReadyNomadClients, template)
219+
}, time.Minute*10)
220+
217221
total, active, err := t.countDroplets(t.ctx, template)
218222
if err != nil {
219223
return nil, fmt.Errorf("failed to describe DigitalOcean droplets: %w", err)

plugin/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ func debounce(key string, fn func(), period time.Duration) {
5050
return
5151
}
5252
}
53-
go fn()
53+
fn()
5454
debounceMap[key] = time.Now()
5555
}

0 commit comments

Comments
 (0)