From 4840a7674c33dcec6c66c012f435d8f5a53b0250 Mon Sep 17 00:00:00 2001 From: Brian Mwangi Date: Tue, 10 Dec 2024 20:09:53 +0300 Subject: [PATCH] Suggested fixes --- server/planning/commands/flag_expired_items.py | 7 ++++--- server/planning/commands/flag_expired_items_test.py | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/planning/commands/flag_expired_items.py b/server/planning/commands/flag_expired_items.py index 46110807c..8575e7b1b 100644 --- a/server/planning/commands/flag_expired_items.py +++ b/server/planning/commands/flag_expired_items.py @@ -11,6 +11,7 @@ from datetime import timedelta, datetime from bson.objectid import ObjectId from contextvars import ContextVar +from typing import Any from planning.events import EventsAsyncService from planning.planning import PlanningAsyncService @@ -135,7 +136,7 @@ async def flag_expired_planning(expiry_datetime: datetime): planning_service = PlanningAsyncService() # Obtain the full list of Planning items that we're to process first - # As subsequent queries will change the list of returnd items + # As subsequent queries will change the list of returned items plans = dict() async for items in planning_service.get_expired_items(expiry_datetime): plans.update({item[ID_FIELD]: item for item in items}) @@ -159,7 +160,7 @@ async def flag_expired_planning(expiry_datetime: datetime): logger.info(f"{log_msg} {len(plans_expired)} Planning items expired: {list(plans_expired)}") -def set_event_plans(events): +def set_event_plans(events: dict[str, dict[str, Any]]) -> None: for plan in get_related_planning_for_events(list(events.keys()), "primary"): for related_event_id in get_related_event_ids_for_planning(plan, "primary"): event = events[related_event_id] @@ -168,7 +169,7 @@ def set_event_plans(events): event["_plans"].append(plan) -def get_event_schedule(event): +def get_event_schedule(event: dict[str, Any]) -> datetime: latest_scheduled = datetime.strptime(event["dates"]["end"], "%Y-%m-%dT%H:%M:%S%z") for plan in event.get("_plans", []): # First check the Planning item's planning date diff --git a/server/planning/commands/flag_expired_items_test.py b/server/planning/commands/flag_expired_items_test.py index 9b9e597d5..0daed83a6 100644 --- a/server/planning/commands/flag_expired_items_test.py +++ b/server/planning/commands/flag_expired_items_test.py @@ -22,19 +22,19 @@ from .flag_expired_items import flag_expired_items_handler now = utcnow() -yesterday = now - timedelta(hours=48) +two_days_ago = now - timedelta(hours=48) active = { "event": {"dates": {"start": now - timedelta(hours=1), "end": now}}, - "overnightEvent": {"dates": {"start": yesterday, "end": now}}, + "overnightEvent": {"dates": {"start": two_days_ago, "end": now}}, "plan": {"planning_date": now}, "coverage": {"planning": {"scheduled": now}}, } expired = { - "event": {"dates": {"start": yesterday, "end": yesterday + timedelta(hours=1)}}, - "plan": {"planning_date": yesterday}, - "coverage": {"planning": {"scheduled": yesterday}}, + "event": {"dates": {"start": two_days_ago, "end": two_days_ago + timedelta(hours=1)}}, + "plan": {"planning_date": two_days_ago}, + "coverage": {"planning": {"scheduled": two_days_ago}}, } @@ -42,7 +42,7 @@ class FlagExpiredItemsTest(TestCase): app_config = { **TestCase.app_config.copy(), # Expire items that are scheduled more than 24 hours from now - "PLANNING_EXPIRY_MINUTES": 1440, + "PLANNING_EXPIRY_MINUTES": 24 * 60, } async def asyncSetUp(self):