Skip to content

Commit

Permalink
Add --scheduled flag to the update command. #332
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Jun 12, 2024
1 parent b3cad78 commit a362623
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ Unreleased

.. FIXME: versionchanged on update_feeds() etc.
* Add ``--scheduled`` flag to the ``update`` command. (:issue:`332`)
* Group mutually-exclusive attributes of :class:`~.FeedUpdateIntent`
into its :attr:`~.FeedUpdateIntent.value` union attribute. (:issue:`332`)

* Fix bug introduced in `version 3.12 <Version 3.12_>`_ causing an assertion error
when there are multiple entries with the same id in the same feed,
or when parallel :meth:`~Reader.update_feeds` calls add the same entry.
Expand Down
13 changes: 10 additions & 3 deletions src/reader/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ def iter_update_status(it, length):
default=None,
help="Only update new (never updated before) feeds.",
)
@click.option(
'--scheduled/--no-scheduled', help="Only update feeds scheduled to be updated."
)
@click.option(
'--workers',
type=click.IntRange(min=1),
Expand All @@ -306,7 +309,7 @@ def iter_update_status(it, length):
@make_log_verbose(True, -2)
@log_command
@pass_reader
def update(reader, url, new, workers, verbose):
def update(reader, url, new, scheduled, workers, verbose):
"""Update one or all feeds.
If URL is not given, update all the feeds.
Expand All @@ -321,8 +324,12 @@ def update(reader, url, new, workers, verbose):
-vvvv: + debug
"""
it = reader.update_feeds_iter(feed=url, new=new, workers=workers)
length = reader.get_feed_counts(feed=url, new=new, updates_enabled=True).total
it = reader.update_feeds_iter(
feed=url, new=new, scheduled=scheduled, workers=workers
)
length = reader.get_feed_counts(
feed=url, new=new, scheduled=scheduled, updates_enabled=True
).total

ok_count = 0
not_modified_count = 0
Expand Down
18 changes: 17 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
import pathlib
from datetime import timedelta

import click
import pytest
Expand Down Expand Up @@ -43,7 +44,7 @@ def reset_logging(pytestconfig):


@pytest.mark.slow
def test_cli(db_path, data_dir):
def test_cli(db_path, data_dir, monkeypatch):
feed_filename = 'full.atom'
feed_path = str(data_dir.joinpath(feed_filename))

Expand Down Expand Up @@ -76,6 +77,21 @@ def invoke(*args):
assert result.exit_code == 0
assert "1 ok, 0 error, 0 not modified; entries: 2 new, 0 modified" in result.output

result = invoke('update')
assert result.exit_code == 0
assert "0 ok, 0 error, 1 not modified; entries: 0 new, 0 modified" in result.output

result = invoke('update', '--scheduled')
assert result.exit_code == 0
assert "0 ok, 0 error, 0 not modified; entries: 0 new, 0 modified" in result.output

now = Reader._now()
monkeypatch.setattr(Reader, '_now', staticmethod(lambda: now + timedelta(hours=1)))

result = invoke('update', '--scheduled')
assert result.exit_code == 0
assert "0 ok, 0 error, 1 not modified; entries: 0 new, 0 modified" in result.output

result = invoke('list', 'feeds')
assert result.exit_code == 0
assert result.output.splitlines() == [feed_path]
Expand Down

0 comments on commit a362623

Please sign in to comment.