reporters
Builders for the progress events of one preprocessing pass or task run.
Module
Submodules
- bitfount.progress_events.reporters.base - Shared behaviour for progress event reporters.
- bitfount.progress_events.reporters.ehr_dataset - Progress events for a preprocessing pass over an EHR dataset.
- bitfount.progress_events.reporters.eligibility_metrics - Eligibility metrics for one completed trial run.
- bitfount.progress_events.reporters.imaging_dataset - Progress events for a preprocessing pass over an imaging dataset.
- bitfount.progress_events.reporters.task_run - Progress events for a task run.
Functions
never_raises
def never_raises(method: Callable[P, None]) ‑> Callable[P, None]:Log and swallow any exception raised by a reporting method.
Arguments
method: The reporting method to guard.
Returns The guarded method.
Classes
EhrDatasetEventReporter
class EhrDatasetEventReporter( sender: ProgressEventSender | None, *, dataset_id: str, dataset_owner_id: str, preprocessing_id: str,):Reports the progress of one preprocessing pass over an EHR dataset.
Arguments
sender: Delivers the events. None makes the reporter a no-op.dataset_id: The dataset being preprocessed.dataset_owner_id: The username of the dataset's owner, which must be the user the sender authenticates as.preprocessing_id: The UUIDv7 identifying this preprocessing pass, fromuuid6.uuid7().
Ancestors
Variables
next_sequence_number : int- The sequence number the next event will carry.
-
sender : ProgressEventSender | None- The sender this reporter hands its events to, if any.Read-only: a caller composing a second reporter for the same run shares this one rather than holding the sender separately.
Methods
error
def error(self, reason: LiteralString, exc: BaseException | None = None) ‑> None:Report that the preprocessing pass failed.
Arguments
reason: A fixed description of what failed. Must be a string literal, so no data can reach it.exc: The exception behind the failure. Only its class name is sent.
patient_listing_completed
def patient_listing_completed(self, patients_listed_count: int) ‑> None:Report that the patient listing step has completed.
Arguments
patients_listed_count: The distinct patients the listing stored. Zero is a valid listing of an empty EHR.
patient_listing_started
def patient_listing_started(self) ‑> None:Report that the patient listing step has started.
preprocessing_started
def preprocessing_started( self, trigger: DatasetPreprocessingStartTrigger.ValueType,) ‑> None:Report that the preprocessing pass has started.
Arguments
trigger: What started the pass.
EligibilityMetricsEventReporter
class EligibilityMetricsEventReporter( sender: ProgressEventSender | None, *, project_id: str, task_run_id: str, dataset_id: str = '', dataset_owner_id: str = '',):Reports the eligibility summary of one task run.
Arguments
sender: Delivers the events. None makes the reporter a no-op.project_id: The project the run belongs to.task_run_id: The UUIDv7 identifying this task run, fromuuid6.uuid7().dataset_id: The dataset the run processed, when the caller knows it. Left empty by a caller reporting through its pod, which stamps it from the grant instead.dataset_owner_id: The username of the dataset's owner, left empty on the same basis.
Ancestors
Variables
next_sequence_number : int- The sequence number the next event will carry.
-
sender : ProgressEventSender | None- The sender this reporter hands its events to, if any.Read-only: a caller composing a second reporter for the same run shares this one rather than holding the sender separately.
Methods
summary
def summary(self, summary: EligibilitySummary) ‑> None:Report the run's eligibility summary.
Arguments
summary: The run's own counts, the deduplicated cohort totals, whether this run's cutover was withheld, and the coverage its verdicts resolved.
EventReporter
class EventReporter(sender: ProgressEventSender | None, start_sequence_number: int):Base for progress event reporters: sequence numbering and safe submission.
Subclasses build their events in methods guarded by never_raises and
hand each one to _submit.
Every event a run emits carries a sequence number: its position among that run's events, counting up by one per event in the order they were reported. Consumers order a run's events by it, since timestamps can tie and events can arrive out of order. A number is never reused within a run, so a retried send overwrites rather than duplicates the stored event. The sequence has a gap wherever an event was dropped.
Arguments
sender: Delivers the events. None makes the reporter a no-op.start_sequence_number: The sequence number of the first event.
Subclasses
Variables
next_sequence_number : int- The sequence number the next event will carry.
-
sender : ProgressEventSender | None- The sender this reporter hands its events to, if any.Read-only: a caller composing a second reporter for the same run shares this one rather than holding the sender separately.
ImagingDatasetEventReporter
class ImagingDatasetEventReporter( sender: ProgressEventSender | None, *, dataset_id: str, dataset_owner_id: str, preprocessing_id: str, start_sequence_number: int = 0,):Reports the progress of one preprocessing pass over an imaging dataset.
Arguments
sender: Delivers the events. None makes the reporter a no-op.dataset_id: The dataset being preprocessed.dataset_owner_id: The username of the dataset's owner, which must be the user the sender authenticates as.preprocessing_id: The UUIDv7 identifying this preprocessing pass, fromuuid6.uuid7().start_sequence_number: The sequence number of the first event. A pass reported from more than one process continues from the previous reporter'snext_sequence_number.
Ancestors
Variables
next_sequence_number : int- The sequence number the next event will carry.
-
sender : ProgressEventSender | None- The sender this reporter hands its events to, if any.Read-only: a caller composing a second reporter for the same run shares this one rather than holding the sender separately.
Methods
error
def error(self, reason: LiteralString, exc: BaseException | None = None) ‑> None:Report that the preprocessing pass failed.
Arguments
reason: A fixed description of what failed. Must be a string literal, so no data can reach it.exc: The exception behind the failure. Only its class name is sent.
file_metadata_completed
def file_metadata_completed( self, files_processed_count: int, files_skipped_count: int, cache_entries_used_count: int = 0,) ‑> None:Report that the file metadata step has completed.
Arguments
files_processed_count: Files the step processed.files_skipped_count: Files the step skipped.cache_entries_used_count: Files answered from the cache.
file_metadata_started
def file_metadata_started(self, files_count: int) ‑> None:Report that the file metadata step has started.
Arguments
files_count: The number of files the step will look at.
preprocessing_started
def preprocessing_started( self, trigger: DatasetPreprocessingStartTrigger.ValueType,) ‑> None:Report that the preprocessing pass has started.
Arguments
trigger: What started the pass.
scan_metadata_completed
def scan_metadata_completed( self, files_processed_count: int, files_skipped_count: int, cache_entries_used_count: int = 0,) ‑> None:Report that the scan metadata step has completed.
Arguments
files_processed_count: Files the step processed.files_skipped_count: Files the step skipped.cache_entries_used_count: Files answered from the cache.
scan_metadata_started
def scan_metadata_started(self, files_count: int) ‑> None:Report that the scan metadata step has started.
Arguments
files_count: The number of files the step will look at.
TaskRunEventReporter
class TaskRunEventReporter( sender: ProgressEventSender | None, *, dataset_id: str, dataset_owner_id: str, project_id: str, task_run_id: str, batch_event_interval_seconds: float = 30.0, clock: Callable[[], float] = <built-in function monotonic>,):Reports the progress of one task run.
Batch events are coalesced per step: a step's batch event is sent at most
once per batch_event_interval_seconds, and the latest batch held back is
sent before the step's completion event, so consumers always see the final
batch.
Arguments
sender: Delivers the events. None makes the reporter a no-op.dataset_id: The dataset the task runs on.dataset_owner_id: The username of the dataset's owner, which must be the user the sender authenticates as.project_id: The project the task belongs to.task_run_id: The UUIDv7 identifying this task run, fromuuid6.uuid7().batch_event_interval_seconds: The shortest time between two batch events for the same step. One interval applies to every step in the run, and each step's interval is timed separately.clock: Monotonic clock in seconds, for tests.
Ancestors
Variables
next_sequence_number : int- The sequence number the next event will carry.
-
sender : ProgressEventSender | None- The sender this reporter hands its events to, if any.Read-only: a caller composing a second reporter for the same run shares this one rather than holding the sender separately.
Methods
completed
def completed(self) ‑> None:Report that the task run has completed.
deferred
def deferred(self) ‑> None:Report that the task run was deferred until the dataset is ready.
error
def error(self, reason: LiteralString, exc: BaseException | None = None) ‑> None:Report that the task run failed.
Arguments
reason: A fixed description of what failed. Must be a string literal, so no data can reach it.exc: The exception behind the failure. Only its class name is sent.
started
def started(self, trigger: TaskRunStartTrigger.ValueType) ‑> None:Report that the task run has started.
Arguments
trigger: What started the run.
step_batch_started
def step_batch_started(self, step_name: str, step_version: str, batch_index: int) ‑> None:Report that a step has started a batch, subject to coalescing.
Arguments
step_name: The step's name in the task template.step_version: The step's version.batch_index: The index of the batch.
step_completed
def step_completed( self, step_name: str, step_version: str, entries_created_count: int, items_skipped_count: int, cache_entries_used_count: int = 0,) ‑> None:Report that a step has completed.
Sends the step's latest held-back batch event first, if there is one.
Arguments
step_name: The step's name in the task template.step_version: The step's version.entries_created_count: Entries the step created.items_skipped_count: Items the step skipped.cache_entries_used_count: Items answered from the cache.
step_started
def step_started( self, step_name: str, step_version: str, batches_count: int, batch_size: int,) ‑> None:Report that a step has started.
Arguments
step_name: The step's name in the task template.step_version: The step's version.batches_count: The number of batches the step will run.batch_size: The number of items in each batch.