-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pause #885
Closed
Closed
Add pause #885
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/alembic/versions/20241114_1400_c99239e3445f_add_pause_functionality.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""add_pause_functionality | ||
|
||
Revision ID: [generate a new revision ID] | ||
Revises: c99709e3648f | ||
Create Date: 2024-11-14 16:00:00.000000 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '[generate a new revision ID]' | ||
down_revision: Union[str, None] = 'c99709e3648f' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Add pause-related columns to MediaItem table | ||
op.add_column('MediaItem', | ||
sa.Column('is_paused', sa.Boolean(), nullable=True, default=False)) | ||
op.add_column('MediaItem', | ||
sa.Column('paused_at', sa.DateTime(), nullable=True)) | ||
op.add_column('MediaItem', | ||
sa.Column('paused_by', sa.String(), nullable=True)) | ||
|
||
# Add index for is_paused column | ||
op.create_index(op.f('ix_mediaitem_is_paused'), 'MediaItem', ['is_paused']) | ||
|
||
|
||
def downgrade() -> None: | ||
# Remove pause-related columns from MediaItem table | ||
op.drop_index(op.f('ix_mediaitem_is_paused'), table_name='MediaItem') | ||
op.drop_column('MediaItem', 'paused_by') | ||
op.drop_column('MediaItem', 'paused_at') | ||
op.drop_column('MediaItem', 'is_paused') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,45 +17,62 @@ def process_event(emitted_by: Service, existing_item: MediaItem | None = None, c | |
no_further_processing: ProcessedEvent = (None, []) | ||
items_to_submit = [] | ||
|
||
#TODO - Reindex non-released badly indexed items here | ||
# Skip processing if item is paused | ||
if existing_item and existing_item.is_paused: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This lines: 20-25 is the only state_transition modification needed, remove the rest. |
||
logger.debug(f"Skipping {existing_item.log_string} - item is paused") | ||
return no_further_processing | ||
|
||
# Process new content items or requested items | ||
if content_item or (existing_item is not None and existing_item.last_state == States.Requested): | ||
next_service = TraktIndexer | ||
logger.debug(f"Submitting {content_item.log_string if content_item else existing_item.log_string} to trakt indexer") | ||
return next_service, [content_item or existing_item] | ||
|
||
# Process partially completed or ongoing items | ||
elif existing_item is not None and existing_item.last_state in [States.PartiallyCompleted, States.Ongoing]: | ||
if existing_item.type == "show": | ||
for season in existing_item.seasons: | ||
if season.last_state not in [States.Completed, States.Unreleased]: | ||
# Skip paused seasons | ||
if not season.is_paused and season.last_state not in [States.Completed, States.Unreleased]: | ||
_, sub_items = process_event(emitted_by, season, None) | ||
items_to_submit += sub_items | ||
elif existing_item.type == "season": | ||
for episode in existing_item.episodes: | ||
if episode.last_state != States.Completed: | ||
# Skip paused episodes | ||
if not episode.is_paused and episode.last_state != States.Completed: | ||
_, sub_items = process_event(emitted_by, episode, None) | ||
items_to_submit += sub_items | ||
|
||
# Process indexed items | ||
elif existing_item is not None and existing_item.last_state == States.Indexed: | ||
next_service = Scraping | ||
if emitted_by != Scraping and Scraping.should_submit(existing_item): | ||
items_to_submit = [existing_item] | ||
elif existing_item.type == "show": | ||
items_to_submit = [s for s in existing_item.seasons if s.last_state != States.Completed and Scraping.should_submit(s)] | ||
# Filter out paused seasons | ||
items_to_submit = [s for s in existing_item.seasons | ||
if not s.is_paused and s.last_state != States.Completed and Scraping.should_submit(s)] | ||
elif existing_item.type == "season": | ||
items_to_submit = [e for e in existing_item.episodes if e.last_state != States.Completed and Scraping.should_submit(e)] | ||
# Filter out paused episodes | ||
items_to_submit = [e for e in existing_item.episodes | ||
if not e.is_paused and e.last_state != States.Completed and Scraping.should_submit(e)] | ||
|
||
# Process scraped items | ||
elif existing_item is not None and existing_item.last_state == States.Scraped: | ||
next_service = Downloader | ||
items_to_submit = [existing_item] | ||
|
||
# Process downloaded items | ||
elif existing_item is not None and existing_item.last_state == States.Downloaded: | ||
next_service = Symlinker | ||
items_to_submit = [existing_item] | ||
|
||
# Process symlinked items | ||
elif existing_item is not None and existing_item.last_state == States.Symlinked: | ||
next_service = Updater | ||
items_to_submit = [existing_item] | ||
|
||
# Process completed items | ||
elif existing_item is not None and existing_item.last_state == States.Completed: | ||
# If a user manually retries an item, lets not notify them again | ||
if emitted_by not in ["RetryItem", PostProcessing]: | ||
|
@@ -73,11 +90,6 @@ def process_event(emitted_by: Service, existing_item: MediaItem | None = None, c | |
if not items_to_submit: | ||
return no_further_processing | ||
else: | ||
|
||
return no_further_processing | ||
|
||
# if items_to_submit and next_service: | ||
# for item in items_to_submit: | ||
# logger.debug(f"Submitting {item.log_string} ({item.id}) to {next_service if isinstance(next_service, str) else next_service.__name__}") | ||
|
||
return next_service, items_to_submit |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up the log string, the latter attribute logs can be debug level if needed