pending_verification
¶
Pending Verification Module.
This module maintains a list of albums that need re-verification in the future. When an album's year cannot be definitely determined from external sources, it is added to this list with a timestamp. On future runs, albums whose verification period has elapsed will be checked again.
File operations (_load_pending_albums, _save_pending_albums) are asynchronous using asyncio's run_in_executor to avoid blocking the event loop.
Refactored: Initial asynchronous loading handled in a separate async initialize method, called by DependencyContainer after service instantiation.
Usage
service = PendingVerificationService(config, console_logger, error_logger) await service.initialize() # IMPORTANT: Call this after creating the instance
Mark album for future verification (now an async method)¶
await service.mark_for_verification("Pink Floyd", "The Dark Side of the Moon")
Check if album needs verification now (now an async method)¶
if await service.is_verification_needed("Pink Floyd", "The Dark Side of the Moon"): # Perform verification pass
Get all pending albums (now an async method)¶
pending_list = await service.get_all_pending_albums()
Get verified album keys (now an async method)¶
verified_keys = await service.get_verified_album_keys()
PendingVerificationService
¶
Service to track albums needing future verification of their release year.
Uses hash-based keys for album data. File operations are asynchronous. Initializes asynchronously.
Initialize the PendingVerificationService.
Does NOT perform file loading here. Use the async initialize method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AppConfig
|
Typed application configuration |
required |
console_logger
|
Logger
|
Logger for console output |
required |
error_logger
|
Logger
|
Logger for error logging. |
required |
Source code in src/services/pending_verification.py
initialize
async
¶
Asynchronously initializes the PendingVerificationService by loading data from the disk.
This method must be called after instantiation.
Source code in src/services/pending_verification.py
generate_album_key
¶
mark_for_verification
async
¶
Mark an album for future verification with reason and optional metadata.
Uses a hash key for storage. Saves asynchronously. If the album is already pending, increments the attempt counter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
reason
|
VerificationReason | str
|
Reason for verification (default: NO_YEAR_FOUND, can be PRERELEASE, etc.) |
NO_YEAR_FOUND
|
metadata
|
dict[str, Any] | None
|
Optional metadata dictionary to store additional information |
None
|
recheck_days
|
int | None
|
Optional override for verification interval in days |
None
|
Source code in src/services/pending_verification.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
get_entry
async
¶
Get pending entry for artist/album if exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
Returns:
| Type | Description |
|---|---|
PendingAlbumEntry | None
|
PendingAlbumEntry if found, None otherwise. |
Source code in src/services/pending_verification.py
get_attempt_count
async
¶
Get current verification attempt count for an album.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of verification attempts made (0 if not in pending list). |
Source code in src/services/pending_verification.py
is_verification_needed
async
¶
Check if an album needs verification now.
Uses the hash key for lookup. Reads from an in-memory cache (async with lock).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the verification period has elapsed, False otherwise |
Source code in src/services/pending_verification.py
remove_from_pending
async
¶
Remove an album from the pending verification list.
Uses the hash key for removal. Saves asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
Source code in src/services/pending_verification.py
get_all_pending_albums
async
¶
Get a list of all pending albums with their verification data.
Retrieves all PendingAlbumEntry objects from the in-memory cache. Accesses the in-memory cache asynchronously with a lock.
Returns:
| Type | Description |
|---|---|
list[PendingAlbumEntry]
|
List of PendingAlbumEntry objects |
Source code in src/services/pending_verification.py
get_pending_albums_by_reason
async
¶
Get pending albums filtered by reason.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
VerificationReason | str
|
The reason to filter by (e.g., PRERELEASE, NO_YEAR_FOUND) |
required |
Returns:
| Type | Description |
|---|---|
list[PendingAlbumEntry]
|
List of PendingAlbumEntry objects matching the reason |
Source code in src/services/pending_verification.py
get_verified_album_keys
async
¶
Get the set of album hash keys that need verification now.
Checks the timestamp in the stored tuple. Accesses the in-memory cache asynchronously with a lock.
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of album hash keys needing verification |
Source code in src/services/pending_verification.py
generate_problematic_albums_report
async
¶
Generate a report of albums that failed to get year after multiple attempts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_attempts
|
int
|
Minimum number of verification attempts to include in the report |
3
|
report_path
|
str | None
|
Path to save the report (uses config default if None) |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of problematic albums found |
Source code in src/services/pending_verification.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
should_auto_verify
async
¶
Check if automatic pending verification should run.
Returns True if: - auto_verify_days has passed since last verification - No previous verification exists - auto_verify_days > 0 (feature enabled)
Returns:
| Type | Description |
|---|---|
bool
|
True if auto-verify should run, False otherwise |
Source code in src/services/pending_verification.py
update_verification_timestamp
async
¶
Update the last pending verification timestamp file.