feat: 自动清理终态 Pod 执行器
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package podbackend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Lifecycle reconciles durable terminal markers into backend cleanup.
|
||||
type Lifecycle struct {
|
||||
Backend Backend
|
||||
Interval time.Duration
|
||||
OnError func(error)
|
||||
}
|
||||
|
||||
func (l Lifecycle) Run(ctx context.Context) error {
|
||||
interval := l.Interval
|
||||
if interval <= 0 {
|
||||
interval = 2 * time.Second
|
||||
}
|
||||
for {
|
||||
if _, err := l.Backend.CleanupTerminated(ctx); err != nil && ctx.Err() == nil && l.OnError != nil {
|
||||
l.OnError(err)
|
||||
}
|
||||
timer := time.NewTimer(interval)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
timer.Stop()
|
||||
return nil
|
||||
case <-timer.C:
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user