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

storage endpoint for deleting multiple runs in one query #25167

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ def wipe(self) -> None:
def delete_run(self, run_id: str) -> None:
return self._storage.run_storage.delete_run(run_id)

def delete_runs(self, run_ids: Sequence[str]) -> None:
return self._storage.run_storage.delete_runs(run_ids)

def migrate(self, print_fn: Optional[PrintFn] = None, force_rebuild_all: bool = False) -> None:
return self._storage.run_storage.migrate(print_fn, force_rebuild_all)

Expand Down
4 changes: 4 additions & 0 deletions python_modules/dagster/dagster/_core/storage/runs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ def wipe(self) -> None:
def delete_run(self, run_id: str) -> None:
"""Remove a run from storage."""

@abstractmethod
def delete_runs(self, run_ids: Sequence[str]) -> None:
"""Remove a list of runs from storage."""

@property
def supports_bucket_queries(self) -> bool:
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ def delete_run(self, run_id: str) -> None:
with self.connect() as conn:
conn.execute(query)

def delete_runs(self, run_ids: Sequence[str]) -> None:
check.list_param(run_ids, "run_ids", of_type=str)
query = db.delete(RunsTable).where(RunsTable.c.run_id.in_(run_ids))
with self.connect() as conn:
conn.execute(query)

def has_job_snapshot(self, job_snapshot_id: str) -> bool:
check.str_param(job_snapshot_id, "job_snapshot_id")
return self._has_snapshot_id(job_snapshot_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,24 @@ def test_delete(self, storage):
storage.delete_run(run_id)
assert list(storage.get_runs()) == []

def test_delete_multiple(self, storage):
if not self.can_delete_runs():
pytest.skip("storage cannot delete runs")

assert storage
run_ids = []
for _ in range(3):
run_id = make_new_run_id()
storage.add_run(TestRunStorage.build_run(run_id=run_id, job_name="some_pipeline"))
run_ids.append(run_id)

storage.add_run(
TestRunStorage.build_run(run_id=make_new_run_id(), job_name="some_pipeline")
)
assert len(storage.get_runs()) == 4
storage.delete_runs(run_ids)
assert len(storage.get_runs()) == 1

def test_delete_with_tags(self, storage: RunStorage):
if not self.can_delete_runs():
pytest.skip("storage cannot delete runs")
Expand All @@ -1051,6 +1069,34 @@ def test_delete_with_tags(self, storage: RunStorage):
assert list(storage.get_runs()) == []
assert run_id not in [key for key, value in storage.get_run_tags(tag_keys=[run_id])]

def test_delete_multiple_with_tags(self, storage: RunStorage):
if not self.can_delete_runs():
pytest.skip("storage cannot delete runs")

assert storage
run_ids = []
for _ in range(3):
run_id = make_new_run_id()
storage.add_run(
TestRunStorage.build_run(
run_id=run_id,
job_name="some_pipeline",
tags={run_id: run_id},
)
)
run_ids.append(run_id)

storage.add_run(
TestRunStorage.build_run(
run_id=make_new_run_id(),
job_name="some_pipeline",
tags={"not_deleted": "true"},
)
)
assert len(storage.get_runs()) == 4
storage.delete_runs(run_ids)
assert len(storage.get_runs()) == 1

def test_wipe_tags(self, storage: RunStorage):
if not self.can_delete_runs():
pytest.skip("storage cannot delete")
Expand Down