Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion monitoring/mock_uss/f3548v21/routes_scd.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def scdsc_notify_operational_intent_details_changed():
conflicts=Conflict.Single, # TODO: detect multiple conflicts
)
)
tx.value.cleanup_notifications()

# Do nothing else because this USS is unsophisticated and polls the DSS for
# every change in its operational intents
Expand Down
45 changes: 45 additions & 0 deletions monitoring/mock_uss/flights/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from implicitdict import ImplicitDict, Optional
from uas_standards.astm.f3548.v21.api import OperationalIntent

from monitoring.mock_uss.app import webapp
from monitoring.mock_uss.user_interactions.notifications import UserNotification
from monitoring.monitorlib.clients.flight_planning.flight_info import FlightInfo
from monitoring.monitorlib.clients.mock_uss.mock_uss_scd_injection_api import (
Expand All @@ -14,6 +15,9 @@

DEADLOCK_TIMEOUT = timedelta(seconds=5)
NOTIFICATIONS_LIMIT = timedelta(hours=1)
DB_CLEANUP_INTERVAL = timedelta(hours=1)
FLIGHTS_LIMIT = timedelta(hours=1)
OPERATIONAL_INTENTS_LIMIT = timedelta(hours=1)


class FlightRecord(ImplicitDict):
Expand Down Expand Up @@ -42,8 +46,49 @@ def cleanup_notifications(self):
> arrow.utcnow().datetime
]

def cleanup_flights(self):
to_cleanup = []

for flight_id, flight in self.flights.items():
if (
flight
and not flight.locked
and flight.op_intent.reference.time_end.value.datetime + FLIGHTS_LIMIT
< arrow.utcnow().datetime
):
to_cleanup.append(flight_id)

for flight_id in to_cleanup:
del self.flights[flight_id]

def cleanup_operational_intents(self):
to_cleanup = []

for op_id, op_intent in self.cached_operations.items():
if (
op_intent.reference.time_end.value.datetime + FLIGHTS_LIMIT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Probably OPERATIONAL_INTENTS_LIMIT? I can adjust in my follow-up PR.

< arrow.utcnow().datetime
):
to_cleanup.append(op_id)

for op_id in to_cleanup:
del self.cached_operations[op_id]


db = SynchronizedValue[Database](
Database(),
decoder=lambda b: ImplicitDict.parse(json.loads(b.decode("utf-8")), Database),
)

TASK_DATABASE_CLEANUP = "flights database cleanup"


@webapp.periodic_task(TASK_DATABASE_CLEANUP)
def database_cleanup() -> None:
with db.transact() as tx:
tx.value.cleanup_notifications()
tx.value.cleanup_flights()
tx.value.cleanup_operational_intents()


webapp.set_task_period(TASK_DATABASE_CLEANUP, DB_CLEANUP_INTERVAL)
2 changes: 0 additions & 2 deletions monitoring/mock_uss/scd_injection/routes_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ def unsuccessful(
)
)

tx.value.cleanup_notifications()

step_name = "returning final successful result"
log("Complete.")

Expand Down
Loading