Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose resetting run boundaries #112

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions nominal/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ def add_connection(self, ref_name: str, connection: Connection | str) -> None:
}
self._clients.run.add_data_sources_to_run(self._clients.auth_header, data_sources, self.rid)

def reset_bounds(self) -> Self:
"""Update the start and end timestamps on the run by inspecting the bounds on
the datasets that compose this run.

This is primarily useful when the set of datasets composing the run change, or
the individual datasets get modified to have more or less data.

NOTE: this only considers datasets when resetting run boundaries. Setting boundaries
on runs containing streaming connections must be done manually using the UI or
the update() function
"""
datasets = self.list_datasets()

# Get the start and end bounds of all composing datasets
dataset_starts = [dataset.bounds.start for _, dataset in datasets if dataset.bounds]
dataset_ends = [dataset.bounds.end for _, dataset in datasets if dataset.bounds]

# If there are no start or end bounds across all input datasets, don't update the
# respective bound of the Run by using None
new_start = min(dataset_starts) if dataset_starts else None
new_end = max(dataset_ends) if dataset_ends else None

# Update the run and return with updated metadata
return self.update(start=new_start, end=new_end)

@classmethod
def _from_conjure(cls, clients: _Clients, run: scout_run_api.Run) -> Self:
return cls(
Expand Down
Loading