Skip to content

Commit

Permalink
Rename exceptions to follow PEP8 (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
linusha authored Jan 21, 2025
2 parents f69b5cc + 6326624 commit e784581
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
12 changes: 4 additions & 8 deletions backend/howtheyvote/pipelines/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ class PipelineResult:
checksum: str | None


class PipelineError(Exception):
class DataUnavailable(Exception): # noqa: N818
pass


class DataUnavailableError(PipelineError):
pass


class DataUnchangedError(PipelineError):
class DataUnchanged(Exception): # noqa: N818
pass


Expand All @@ -45,9 +41,9 @@ def run(self) -> PipelineResult:
try:
self._run()
status = PipelineStatus.SUCCESS
except DataUnavailableError:
except DataUnavailable:
status = PipelineStatus.DATA_UNAVAILABLE
except DataUnchangedError:
except DataUnchanged:
status = PipelineStatus.DATA_UNCHANGED
except ScrapingError:
status = PipelineStatus.FAILURE
Expand Down
10 changes: 4 additions & 6 deletions backend/howtheyvote/pipelines/rcv_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
from ..store import Aggregator, BulkWriter, index_records, map_vote, map_vote_group
from .common import (
BasePipeline,
DataUnavailableError,
DataUnchangedError,
DataUnavailable,
DataUnchanged,
compute_response_checksum,
)

Expand Down Expand Up @@ -99,15 +99,13 @@ def _scrape_rcv_list(self) -> None:
try:
fragments = scraper.run()
except NoWorkingUrlError as exc:
raise DataUnavailableError("Pipeline data source is not available") from exc
raise DataUnavailable("Pipeline data source is not available") from exc

if (
self.last_run_checksum is not None
and self.last_run_checksum == compute_response_checksum(scraper.response)
):
raise DataUnchangedError(
"The data source hasn't changed since the last pipeline run."
)
raise DataUnchanged("The data source hasn't changed since the last pipeline run.")

self.checksum = compute_response_checksum(scraper.response)

Expand Down
12 changes: 6 additions & 6 deletions backend/howtheyvote/worker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from ..query import session_is_current_at
from .worker import (
SkipPipelineError,
SkipPipeline,
Weekday,
Worker,
last_pipeline_run_checksum,
Expand All @@ -35,10 +35,10 @@ def op_rcv_midday() -> PipelineResult:
today = datetime.date.today()

if not _is_session_day(today):
raise SkipPipelineError()
raise SkipPipeline()

if pipeline_ran_successfully(RCVListPipeline, today):
raise SkipPipelineError()
raise SkipPipeline()

pipeline = RCVListPipeline(term=config.CURRENT_TERM, date=today)
return pipeline.run()
Expand All @@ -53,10 +53,10 @@ def op_rcv_evening() -> PipelineResult:
today = datetime.date.today()

if not _is_session_day(today):
raise SkipPipelineError()
raise SkipPipeline()

if pipeline_ran_successfully(RCVListPipeline, today, count=2):
raise SkipPipelineError()
raise SkipPipeline()

last_run_checksum = last_pipeline_run_checksum(
pipeline=RCVListPipeline,
Expand All @@ -76,7 +76,7 @@ def op_press() -> PipelineResult:
today = datetime.date.today()

if not _is_session_day(today):
raise SkipPipelineError()
raise SkipPipeline()

pipeline = PressPipeline(date=today, with_rss=True)
return pipeline.run()
Expand Down
4 changes: 2 additions & 2 deletions backend/howtheyvote/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)


class SkipPipelineError(Exception):
class SkipPipeline(Exception): # noqa: N818
pass


Expand Down Expand Up @@ -179,7 +179,7 @@ def wrapped_handler() -> None:
result = handler()
status = result.status
checksum = result.checksum
except SkipPipelineError:
except SkipPipeline:
# Do not log skipped pipeline runs
return
except Exception:
Expand Down

0 comments on commit e784581

Please sign in to comment.