MCPcopy
hub / github.com/wavetermdev/waveterm / pruneUnusedJobs

Function pruneUnusedJobs

pkg/jobcontroller/jobcontroller.go:317–347  ·  view source on GitHub ↗
(previousCandidates []string)

Source from the content-addressed store, hash-verified

315}
316
317func pruneUnusedJobs(previousCandidates []string) []string {
318 ctx, cancelFn := context.WithTimeout(context.Background(), 30*time.Second)
319 defer cancelFn()
320
321 allJobs, err := wstore.DBGetAllObjsByType[*waveobj.Job](ctx, waveobj.OType_Job)
322 if err != nil {
323 log.Printf("[jobpruner] error getting all jobs: %v", err)
324 return previousCandidates
325 }
326
327 var currentCandidates []string
328 for _, job := range allJobs {
329 if job.JobManagerStatus == JobManagerStatus_Done && job.AttachedBlockId == "" {
330 currentCandidates = append(currentCandidates, job.OID)
331 }
332 }
333
334 jobsToDelete := utilfn.StrSetIntersection(previousCandidates, currentCandidates)
335 if len(previousCandidates) > 0 || len(currentCandidates) > 0 {
336 log.Printf("[jobpruner] prev=%d current=%d deleting=%d", len(previousCandidates), len(currentCandidates), len(jobsToDelete))
337 }
338
339 for _, jobId := range jobsToDelete {
340 err := DeleteJob(ctx, jobId)
341 if err != nil {
342 log.Printf("[jobpruner] error deleting job %s: %v", jobId, err)
343 }
344 }
345
346 return currentCandidates
347}
348
349func handleRouteUpEvent(event *wps.WaveEvent) {
350 handleRouteEvent(event, JobConnStatus_Connected)

Callers 1

jobPruningWorkerFunction · 0.85

Calls 3

DBGetAllObjsByTypeFunction · 0.92
StrSetIntersectionFunction · 0.92
DeleteJobFunction · 0.85

Tested by

no test coverage detected