checkFolderStats runs at an interval to see if any folders need work done on them. This runs on an interval ticker in the main go routine.
(now time.Time)
| 560 | // checkFolderStats runs at an interval to see if any folders need work done on them. |
| 561 | // This runs on an interval ticker in the main go routine. |
| 562 | func (u *Unpackerr) checkFolderStats(now time.Time) { |
| 563 | for name, folder := range u.folders.Folders { |
| 564 | switch elapsed := now.Sub(folder.updated); { |
| 565 | case WAITING == folder.status && elapsed >= u.StartDelay.Duration: |
| 566 | // The folder hasn't been written to in a while, extract it. |
| 567 | u.extractTrackedItem(name, folder, now) |
| 568 | case EXTRACTEDNOTHING == folder.status: |
| 569 | // Wait until this item hasn't been touched for a while, so it doesn't re-queue. |
| 570 | if now.Sub(folder.updated) > u.StartDelay.Duration { |
| 571 | // Ignore "no compressed files" errors for folders. |
| 572 | delete(u.Map, name) |
| 573 | delete(u.folders.Folders, name) |
| 574 | } |
| 575 | case EXTRACTFAILED == folder.status && elapsed >= u.RetryDelay.Duration && |
| 576 | (u.MaxRetries == 0 || folder.retries < u.MaxRetries): |
| 577 | u.Retries++ |
| 578 | folder.retries++ |
| 579 | folder.updated = now |
| 580 | folder.status = WAITING |
| 581 | u.Printf("[Folder] Re-starting Failed Extraction: %s (%d/%d, failed %v ago)", |
| 582 | folder.config.Path, folder.retries, u.MaxRetries, elapsed.Round(time.Second)) |
| 583 | case EXTRACTFAILED == folder.status && folder.retries < u.MaxRetries: |
| 584 | // This empty block is to avoid deleting an item that needs more retries. |
| 585 | case folder.status > EXTRACTING && folder.config.DeleteAfter.Duration <= 0: |
| 586 | // if DeleteAfter is 0 we don't delete anything. we are done. |
| 587 | u.updateQueueStatus(&newStatus{Name: name, Status: DELETED, Resp: nil}, now, false) |
| 588 | delete(u.folders.Folders, name) |
| 589 | case EXTRACTED == folder.status && elapsed >= folder.config.DeleteAfter.Duration: |
| 590 | u.deleteAfterReached(name, now, folder) |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | //nolint:wsl |
| 596 | func (u *Unpackerr) deleteAfterReached(name string, now time.Time, folder *Folder) { |
no test coverage detected