MCPcopy Create free account
hub / github.com/Unpackerr/unpackerr / checkExtractDone

Method checkExtractDone

pkg/unpackerr/handlers.go:176–213  ·  view source on GitHub ↗

checkExtractDone checks if an extracted and imported item needs to be deleted. Or if an extraction failed and needs to be restarted. This runs at a short interval to check for extraction state changes, and should return quickly. nolint:cyclop,wsl

(now time.Time)

Source from the content-addressed store, hash-verified

174//
175//nolint:cyclop,wsl
176func (u *Unpackerr) checkExtractDone(now time.Time) {
177 for name, item := range u.Map {
178 switch elapsed := now.Sub(item.Updated); {
179 case item.Status == DELETED && elapsed >= item.DeleteDelay:
180 // Remove the item from history some time after it's deleted.
181 u.Finished++
182 delete(u.Map, name)
183 u.Printf("[%s] Finished, Removed History: %v", item.App, name)
184 case item.App == FolderString:
185 continue // folders are handled in folder.go.
186 case item.Status == EXTRACTFAILED && elapsed >= u.RetryDelay.Duration &&
187 (u.MaxRetries == 0 || item.Retries < u.MaxRetries):
188 u.Retries++
189 item.Retries++
190 item.Status = WAITING
191 item.Updated = now
192 u.Printf("[%s] Extract failed %v ago, triggering restart (%d/%d): %v",
193 item.App, elapsed.Round(time.Second), item.Retries, u.MaxRetries, name)
194 case item.Status == IMPORTED && elapsed >= item.DeleteDelay:
195 var webhook bool
196
197 if item.DeleteOrig {
198 u.delChan <- &fileDeleteReq{Paths: []string{item.Path}}
199 webhook = true
200 } else if item.Resp != nil && len(item.Resp.NewFiles) > 0 && item.DeleteDelay >= 0 {
201 // Delete extracted files and purge empty parents up to and including the download path.
202 u.delChan <- &fileDeleteReq{
203 Paths: item.Resp.NewFiles,
204 PurgeEmptyParent: true,
205 PurgeEmptyRoot: item.Path,
206 }
207 webhook = true
208 }
209
210 u.updateQueueStatus(&newStatus{Name: name, Status: DELETED, Resp: item.Resp}, now, webhook)
211 }
212 }
213}
214
215// handleXtractrCallback handles callbacks from the xtractr library for starr apps (not folders).
216// This takes the provided info and logs it then sends it the queue update method.

Callers 1

RunMethod · 0.95

Calls 2

updateQueueStatusMethod · 0.95
PrintfMethod · 0.65

Tested by

no test coverage detected