Skip to content

Commit

Permalink
🎉 demo housekeeper (#3797)
Browse files Browse the repository at this point in the history
* 🎉 demo housekeeper

* reflect new names

* wip
  • Loading branch information
lucasrodes authored and Tuna Acisu committed Feb 5, 2025
1 parent 5209a2e commit 287b02c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
20 changes: 17 additions & 3 deletions apps/housekeeper/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Keep things in OWID catalog clean by regularly checking and reviewing content."""

from typing import Optional

import click
from rich_click import RichCommand

Expand All @@ -18,12 +20,24 @@


@click.command("housekeeper", cls=RichCommand, help=__doc__)
@click.option("--review-type", "-t", type=click.Choice(REVIEW_TYPES, case_sensitive=False))
def main(review_type: str):
@click.option(
"--review-type",
"-t",
type=click.Choice(REVIEW_TYPES, case_sensitive=False),
help="Type of the review",
)
@click.option(
"--channel",
"-c",
type=str,
help=f"Name of the slack channel to send the message two. If None, {CHANNEL_NAME} will be used",
)
def main(review_type: str, channel: Optional[str] = None):
channel_name = CHANNEL_NAME if channel is None else channel
# Review charts
if review_type == "chart":
send_slack_chart_review(
channel_name=CHANNEL_NAME,
channel_name=channel_name,
slack_username=SLACK_USERNAME,
icon_emoji=ICON_EMOJI,
)
4 changes: 2 additions & 2 deletions apps/housekeeper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

def get_reviews_id(object_type: str):
with Session(OWID_ENV.engine) as session:
return gm.HousekeepingSuggestedReview.load_reviews_object_id(session, object_type=object_type)
return gm.HousekeeperReview.load_reviews_object_id(session, object_type=object_type)


def add_reviews(object_type: str, object_id: int):
with Session(OWID_ENV.engine) as session:
gm.HousekeepingSuggestedReview.add_review(
gm.HousekeeperReview.add_review(
session=session,
object_type=object_type,
object_id=object_id,
Expand Down
6 changes: 3 additions & 3 deletions etl/grapher/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def create_table(cls, engine: Engine, if_exists: Literal["fail", "replace", "ski
raise ValueError(f"Unrecognized value for if_exists: {if_exists}")


class HousekeepingSuggestedReview(Base):
__tablename__ = "housekeeping_suggested_reviews"
class HousekeeperReview(Base):
__tablename__ = "housekeeper_reviews"

id: Mapped[int] = mapped_column(
Integer,
Expand All @@ -153,7 +153,7 @@ class HousekeepingSuggestedReview(Base):
objectId: Mapped[int] = mapped_column(Integer, nullable=False)

@classmethod
def load_reviews(cls, session: Session, object_type: Optional[str] = None) -> list["HousekeepingSuggestedReview"]:
def load_reviews(cls, session: Session, object_type: Optional[str] = None) -> list["HousekeeperReview"]:
if object_type is None:
vars = session.scalars(select(cls)).all()
return list(vars)
Expand Down
11 changes: 8 additions & 3 deletions scripts/housekeeper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ start_time=$(date +%s)

HOUR=$(TZ=Europe/Berlin date +%H)
echo '--- Keep OWID clean'
cd /home/owid/etl
if [ "$HOUR" -eq "01" ]; then
uv run etl d housekeeper --review-type chart
# cd /home/owid/etl
if [ "$HOUR" -eq "03" ]; then
echo "--- Suggesting chart reviews..."
if [ -n "$1" ]; then
uv run etl d housekeeper --review-type chart --channel "$1"
else
uv run etl d housekeeper --review-type chart
fi
fi

end_time=$(date +%s)
Expand Down

0 comments on commit 287b02c

Please sign in to comment.