fix(daemon): regrab a failed grab once unblacklisted
ci / web (pull_request) Successful in 29s
e2e / e2e (pull_request) Successful in 2m12s
ci / rust (pull_request) Successful in 2m35s
ci / image (pull_request) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-11-15 15:42:59 +00:00
co-authored by Claude Opus 5.5
parent 3faa6ea8aa
commit d55c983620
2 changed files with 38 additions and 4 deletions
@@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "INSERT INTO grabs (release_id, target_kind, target_id, infohash, state)\n VALUES (?, ?, ?, ?, 'sent')\n ON CONFLICT (infohash) DO UPDATE SET\n release_id = excluded.release_id,\n target_kind = excluded.target_kind,\n target_id = excluded.target_id,\n state = 'sent',\n grabbed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),\n imported_at = NULL\n WHERE grabs.state = 'vanished'\n OR (grabs.target_kind = 'movie'\n AND NOT EXISTS (SELECT 1 FROM movies WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'season'\n AND NOT EXISTS (SELECT 1 FROM seasons WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'episode'\n AND NOT EXISTS (SELECT 1 FROM episodes WHERE id = grabs.target_id))\n RETURNING id AS \"id!: i64\"",
"query": "INSERT INTO grabs (release_id, target_kind, target_id, infohash, state)\n VALUES (?, ?, ?, ?, 'sent')\n ON CONFLICT (infohash) DO UPDATE SET\n release_id = excluded.release_id,\n target_kind = excluded.target_kind,\n target_id = excluded.target_id,\n state = 'sent',\n grabbed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),\n imported_at = NULL\n WHERE grabs.state IN ('vanished', 'failed')\n OR (grabs.target_kind = 'movie'\n AND NOT EXISTS (SELECT 1 FROM movies WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'season'\n AND NOT EXISTS (SELECT 1 FROM seasons WHERE id = grabs.target_id))\n OR (grabs.target_kind = 'episode'\n AND NOT EXISTS (SELECT 1 FROM episodes WHERE id = grabs.target_id))\n RETURNING id AS \"id!: i64\"",
"describe": {
"columns": [
{
@@ -22,5 +22,5 @@
null
]
},
"hash": "2aeb5f9dab4a62d4cc463a05c0636c379b9c5a1cebee9dfa61df2162f2c64383"
"hash": "d026eb7f157b69a3261395d5f20e360df98cfdaf1d4a33c9f163528f42e8d997"
}
+36 -2
View File
@@ -700,7 +700,9 @@ impl Grabber {
// `infohash` is unique, so re-grabbing the same release conflicts
// with its own earlier row. A `sent`/`downloaded` row is the restart
// case and is left alone; a `vanished` one (§86) is reclaimed, since
// nothing blacklisted the release.
// nothing blacklisted the release. So is a `failed` one: a hard fail
// blacklists its torrent, so reaching here means the operator lifted
// that blacklisting (§6.3) and wants the release again.
//
// A row whose target no longer exists is reclaimed too, whatever its
// state. Deleting a title used to leave its grabs behind, and one of
@@ -721,7 +723,7 @@ impl Grabber {
state = 'sent',
grabbed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
imported_at = NULL
WHERE grabs.state = 'vanished'
WHERE grabs.state IN ('vanished', 'failed')
OR (grabs.target_kind = 'movie'
AND NOT EXISTS (SELECT 1 FROM movies WHERE id = grabs.target_id))
OR (grabs.target_kind = 'season'
@@ -2076,6 +2078,38 @@ mod tests {
assert_eq!(state, "downloading");
}
/// A hard-failed grab whose blacklisting the operator lifted (§6.3) is
/// reclaimed by the next grab of the same torrent, instead of the
/// `failed` row silently swallowing it.
#[tokio::test]
async fn an_unblacklisted_failed_grab_can_regrab_the_same_infohash() {
let (_dir, database) = wanted_movie().await;
let indexer = prowlarr().await;
let (downloader, fake) = qbit().await;
let action = action(&indexer, &downloader);
action.tick(&database).await.unwrap();
sqlx::query("UPDATE grabs SET state = 'failed'")
.execute(database.pool())
.await
.unwrap();
sqlx::query("UPDATE movies SET state = 'missing' WHERE id = 1")
.execute(database.pool())
.await
.unwrap();
fake.torrents.lock().unwrap().clear();
let outcomes = action.tick(&database).await.unwrap();
assert_eq!(outcomes.len(), 1, "a fresh grab");
let grabs = grabs(&database).await;
assert_eq!(
grabs.len(),
1,
"the failed row is reclaimed, not duplicated"
);
assert_eq!(grabs[0].2, "sent");
}
/// A grab row left behind by a deleted title holds the release's unique
/// infohash. Re-adding the title and grabbing the same release used to
/// record nothing at all: the conflict hit a row in `sent`, which is only