Skip to content

SlotService

Handles Slot retrieval workflow.

backend.services.slot_service.SlotService

Service responsible for: - Fetching slot data from remote source - Parsing slot information - Persisting slots into database - Handling slot state updates

delete_completed_slots

delete_completed_slots()

Deletes completed (DONE) slots.

:return: Number of rows deleted.

get_active_slot

get_active_slot()

Return the current active slot if available.

Workflow: 1. Reconcile expired slot states 2. Return existing ACTIVE slot if present 3. Claim next eligible PENDING slot if applicable

:return: Active DownlinkSlot if available, else None

get_future_slots

get_future_slots(downlink_start_utc, downlink_end_utc)

Returns future slots - which are not yet started.

Could be utilized when there's no current ACTIVE slot, and we want to see next upcoming slots.

:param downlink_start_utc: starting UTC timestamp (expected to be current timestamp) :param downlink_end_utc: Upper bound UTC timestamp :return: Return list of slot domain entities.

get_next_active_slot

get_next_active_slot()

Returns the next active slot if present. This is intended to be used after no active slot is found and next upcoming active slot is required.

:return: Active DownlinkSlot if available, else None

get_past_slots

get_past_slots(downlink_start_utc, downlink_end_utc)

get slots whose time window falls within the time period between start and end.

:param downlink_start_utc: lower bound timestamp :param downlink_end_utc: upper bound timestamp (expected to be current timestamp) :return: List of DownlinkSlot domain entities ordered by bot_utc

mark_slot_done

mark_slot_done(slot)

Mark slot as completed.

:param slot: slot domain entity :return: updated slot domain entity (if successful).

next_active_slot_in

next_active_slot_in()

Returns the time remaining until the start of next slot. This is independent of if currently there exists an ACTIVE slot or not.

Logic: - find the earliest PENDING slot whose start time is in the future - return the time difference between now and its start time.

reconcile_slot_states

reconcile_slot_states()

Reconcile slot lifecycle states based on current UTC time.

Transitions: - ACTIVE -> MISSED - PENDING -> MISSED

:return: None

sync_slots

sync_slots(cancel_event)

Fetch slot data from remote source and update database. :param cancel_event: event to track cancel request from user.

:return: number of new slots inserted