(previousCandidates []string)
| 315 | } |
| 316 | |
| 317 | func 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 | |
| 349 | func handleRouteUpEvent(event *wps.WaveEvent) { |
| 350 | handleRouteEvent(event, JobConnStatus_Connected) |
no test coverage detected