Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,28 +476,31 @@ the wait when no row reads `queued` and one not paused itself, and not at Force
priority, reads `downloading` or `propagating`; where its rows cannot tell, the
switch and the history are read, as `pause_downloads` says. A download not
paused itself is then told to wait, and to resume the queue if it stays paused,
with no step; one paused itself is told that too, and resumed by its id. When it
reads a pause by hand instead, the queue's remedy adds that SABnzbd may be
waiting so as well. NZBGet pauses a download's extra repair files on
add, and the *arrs read a download whose paused files are all it has left as
paused, into post-processing, so a row there (`verifying`, `repairing`,
`extracting`, `moving`) is told to wait, unless something holds it. NZBGet's
paused post-processing can hold it, waiting for it, in a par check or repair, or
running a script: then it is told to resume post-processing in NZBGet. A paused
queue can hold repair files a repair asked for: then it is told to resume the
queue, and post-processing in NZBGet as well when that is paused too. Any other
client row gets no resume, since qBittorrent's resume without an `id` restarts
every torrent: one in progress is told that nothing there holds the download
back, and one whose status the adapter could not map only to check the client. A
torrent stopped with nothing left to download has finished: it waits on the
import like a seeding one. A release the *arr holds back and has sent to no
client (`delay`: a delay profile, a usenet minimum age, an indexer disabled
after failures or another release already pending, among others) blocks with no
remedy, like a download in progress, and `downloadClientUnavailable`, a release
the *arr could not send, asks you to check its download clients. A message on an
*arr's row that is not in trouble (NZBGet's PAR status on a finished download,
"qBittorrent is downloading metadata") is not read as a fault; a row still on
its way shows it after "Still downloading".
with no step; one paused itself is told that too, and resumed by its id. For up
to ten seconds after the wait ends, a queue paused by hand can still read as the
wait, since a history read that shows a download in post-processing is shared
that long (see `pause_downloads`). When it reads a pause by hand instead, the
queue's remedy adds that SABnzbd may be waiting so as well. NZBGet pauses a
download's extra repair files on add, and the *arrs read a download whose paused
files are all it has left as paused, into post-processing, so a row there
(`verifying`, `repairing`, `extracting`, `moving`) is told to wait, unless
something holds it. NZBGet's paused post-processing can hold it, waiting for it,
in a par check or repair, or running a script: then it is told to resume
post-processing in NZBGet. A paused queue can hold repair files a repair asked
for: then it is told to resume the queue, and post-processing in NZBGet as well
when that is paused too. Any other client row gets no resume, since
qBittorrent's resume without an `id` restarts every torrent: one in progress is
told that nothing there holds the download back, and one whose status the
adapter could not map only to check the client. A torrent stopped with nothing
left to download has finished: it waits on the import like a seeding one. A
release the *arr holds back and has sent to no client (`delay`: a delay profile,
a usenet minimum age, an indexer disabled after failures or another release
already pending, among others) blocks with no remedy, like a download in
progress, and `downloadClientUnavailable`, a release the *arr could not send,
asks you to check its download clients. A message on an *arr's row that is not
in trouble (NZBGet's PAR status on a finished download, "qBittorrent is
downloading metadata") is not read as a fault; a row still on its way shows it
after "Still downloading".

A finished download waiting on its import is read by the *arr's own import
state (`importState` in get_queue). At `importBlocked` the *arr stopped and does
Expand Down Expand Up @@ -2724,11 +2727,11 @@ shows none is not kept, since post-processing can start at any moment. A pause
is sent, and keeps the queue paused once the wait ends, unless a `queued` row
shows it paused by hand already; a resume is sent too, since a manual pause can
lie behind the wait, and its preview says that downloading starts once the wait
ends. A pause by hand with no `queued` row that leaves the rows looking like the
wait, or that comes while the switch is on and a download is in post-processing,
reads the same way, since neither tells the two apart: a second pause is then
offered, and `diagnose_media` still says SABnzbd resumes by itself. An `id` the
client does not have is refused as not found.
ends, if SABnzbd is waiting. A pause by hand with no `queued` row that leaves
the rows looking like the wait, or that comes while the switch is on and a
download is in post-processing, reads the same way, since neither tells the two
apart: a second pause is then offered, and `diagnose_media` still says SABnzbd
resumes by itself. An `id` the client does not have is refused as not found.

**Unverified live** (qBittorrent): pause, resume and the speed limit.

Expand Down Expand Up @@ -2788,12 +2791,15 @@ behind the wait. A job the client pauses itself is told to resume it by its `id`
queue's hold with one more status read, and SABnzbd, when its queue reads
paused, with a read of the whole queue where the first read does not settle it,
since the job's own row often cannot tell the wait from a pause, and of its
switch and history where the rows cannot tell (see `pause_downloads`). An NZBGet
download the retry finds in post-processing is said to be there, in the words of
its stage (`stage`, such as "queued for post-processing"), with a paused queue
holding the repair files it asked for (`queue_paused`) and paused
post-processing (`post_processing_paused`) named; one done with post-processing
is followed to its history, which says how it ended.
switch and history where the rows cannot tell (see `pause_downloads`). For up to
ten seconds after the wait ends, a job in a queue paused by hand can still be
said to wait for it (`post_processing_wait`), since a history read that shows a
download in post-processing is shared that long. An NZBGet download the retry
finds in post-processing is said to be there, in the words of its stage
(`stage`, such as "queued for post-processing"), with a paused queue holding the
repair files it asked for (`queue_paused`) and paused post-processing
(`post_processing_paused`) named; one done with post-processing is followed to
its history, which says how it ended.

**Remove Failed must be off.** Radarr and Sonarr's "Remove Failed" setting
(Settings, Download Clients, on by default) deletes a failed job from the client
Expand Down
9 changes: 7 additions & 2 deletions src/tools/retryDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ const HOLD_FIELDS: Readonly<Record<QueueHold, readonly HoldFlag[]>> = {
const HOLD_FLAGS = ['queue_paused', 'post_processing_wait', 'post_processing_paused'] as const;
type HoldFlag = (typeof HOLD_FLAGS)[number];

/** The hold whose fields are exactly the flags set, whatever their order: how `applied` reads a result's hold back. */
export const holdOf = (flags: Partial<Record<HoldFlag, true>>): QueueHold | undefined =>
(Object.keys(HOLD_FIELDS) as QueueHold[]).find(hold =>
HOLD_FLAGS.every(flag => (flags[flag] === true) === HOLD_FIELDS[hold].includes(flag))
);

/** Where it ended up, in words. A finished rerun with no event is one an *arr
* already took out of the client's history, not a failure. */
const describeOutcome = (outcome: Pick<RetryOutcome, 'id' | 'state' | 'status' | 'stage' | 'event' | 'heldBy' | 'pausedItself'>, client: string) => {
Expand Down Expand Up @@ -275,8 +281,7 @@ export function registerRetryDownload(server: McpServer, context: WriteContext,
describeOutcome(
{
...r,
// The hold whose fields are exactly the ones set, whatever their order.
...withHold((Object.keys(HOLD_FIELDS) as QueueHold[]).find(hold => HOLD_FLAGS.every(flag => (r[flag] === true) === HOLD_FIELDS[hold].includes(flag)))),
...withHold(holdOf(r)),
...(r.paused_itself === true ? { pausedItself: true } : {})
},
r.service
Expand Down
16 changes: 15 additions & 1 deletion test/retryDownload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SabnzbdAdapter } from '../src/services/sabnzbd.ts';
import { WhisparrAdapter } from '../src/services/whisparr.ts';
import type { DownloadTrace, RetryOutcome, RetryTarget, ServiceAdapter } from '../src/services/types.ts';
import type { LibraryLoader } from '../src/tools/library.ts';
import { registerRetryDownload } from '../src/tools/retryDownload.ts';
import { holdOf, registerRetryDownload } from '../src/tools/retryDownload.ts';
import type { WriteToolResult } from '../src/tools/write.ts';
import { jsonResponse } from './helpers/serve.ts';

Expand Down Expand Up @@ -485,3 +485,17 @@ describe('retry_download', () => {
expect(structuredContent.effects.join(' ')).toMatch(/added from a URL/);
});
});

describe('holdOf', () => {
it.each<[Parameters<typeof holdOf>[0], ReturnType<typeof holdOf>]>([
[{ queue_paused: true }, 'queue'],
[{ post_processing_wait: true }, 'postProcessing'],
[{ post_processing_paused: true }, 'postPaused'],
[{ queue_paused: true, post_processing_paused: true }, 'queueAndPostPaused'],
[{}, undefined],
// No hold has both, so neither one-flag hold is a match.
[{ queue_paused: true, post_processing_wait: true }, undefined]
])('reads %j back as %s', (flags, hold) => {
expect(holdOf(flags)).toBe(hold);
});
});
Loading