2026-04-15 14:19:21 +08:00
|
|
|
package scheduler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
tenantapp "github.com/geo-platform/tenant-api/internal/tenant/app"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type KnowledgeDeletedCleanupWorker struct {
|
|
|
|
|
service *tenantapp.KnowledgeService
|
|
|
|
|
interval time.Duration
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewKnowledgeDeletedCleanupWorker(service *tenantapp.KnowledgeService) *KnowledgeDeletedCleanupWorker {
|
|
|
|
|
return &KnowledgeDeletedCleanupWorker{
|
|
|
|
|
service: service,
|
|
|
|
|
interval: 15 * time.Second,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *KnowledgeDeletedCleanupWorker) Start(ctx context.Context) {
|
2026-04-24 22:20:43 +08:00
|
|
|
go w.Run(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *KnowledgeDeletedCleanupWorker) Run(ctx context.Context) {
|
2026-04-15 14:19:21 +08:00
|
|
|
if w == nil || w.service == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-24 22:20:43 +08:00
|
|
|
w.run(ctx)
|
2026-04-15 14:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *KnowledgeDeletedCleanupWorker) run(ctx context.Context) {
|
|
|
|
|
w.service.RunDeletedCleanupSweep()
|
|
|
|
|
|
|
|
|
|
ticker := time.NewTicker(w.interval)
|
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return
|
|
|
|
|
case <-ticker.C:
|
|
|
|
|
w.service.RunDeletedCleanupSweep()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|