lablup / lablup/backend.ai

Implement Purger pattern for scheduling history cleanup

Open
#7,263 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
17h 7m
Merged PRs (30d)
358

Description

## Overview

Add `Purger` class similar to `Querier` for delete operations on scheduling history tables.

## Background

Currently, scheduling history tables only have record and search operations. As history data accumulates over time, we need cleanup capabilities.

## Requirements

### Purger Class

```python
@dataclass
class Purger:
conditions: list[Condition]
```

### Repository Methods

- `purge_session_history(purger: Purger) -> int`
- `purge_kernel_history(purger: Purger) -> int`
- `purge_deployment_history(purger: Purger) -> int`
- `purge_route_history(purger: Purger) -> int`

### Condition Examples

- By entity ID (session_id, kernel_id, etc.)
- By date (created_before, created_after)

## Usage Example

```python
# Purge by entity
purger = Purger(conditions=[SessionHistoryConditions.by_session_id(session_id)])
deleted_count = await repo.purge_session_history(purger)

# Bulk purge old records
purger = Purger(conditions=[SessionHistoryConditions.created_before(cutoff_date)])
deleted_count = await repo.purge_session_history(purger)
```

## Parent Epic

BA-3060

JIRA Issue: BA-3337

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.