Skip to content

Commit 9d5d087

Browse files
committed
Address code review comments and slight improved logging.
1 parent 2c4821a commit 9d5d087

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

components/clp-package-utils/clp_package_utils/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def validate_dataset_name(clp_table_prefix: str, dataset_name: str) -> None:
582582
)
583583

584584

585-
def is_retention_configured(clp_config: CLPConfig) -> bool:
585+
def is_retention_period_configured(clp_config: CLPConfig) -> bool:
586586
if clp_config.archive_output.retention_period is not None:
587587
return True
588588

components/clp-package-utils/clp_package_utils/scripts/start_clp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
get_clp_home,
5656
is_container_exited,
5757
is_container_running,
58-
is_retention_configured,
58+
is_retention_period_configured,
5959
load_config_file,
6060
validate_and_load_db_credentials_file,
6161
validate_and_load_queue_credentials_file,
@@ -1063,7 +1063,7 @@ def start_garbage_collector(
10631063
):
10641064
component_name = GARBAGE_COLLECTOR_NAME
10651065

1066-
if not is_retention_configured(clp_config):
1066+
if not is_retention_period_configured(clp_config):
10671067
logger.info(f"Retention period is not configured, skipping {component_name} creation...")
10681068
return
10691069

components/job-orchestration/job_orchestration/garbage_collector/search_result_garbage_collector.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ def _collect_and_sweep_expired_search_results(
6363
job_results_collection.drop()
6464
deleted_job_ids.append(int(job_id))
6565

66-
logger.debug(f"Deleted search results of job(s): {deleted_job_ids}.")
67-
66+
if len(deleted_job_ids) != 0:
67+
logger.debug(f"Deleted search results of job(s): {deleted_job_ids}.")
68+
else:
69+
logger.debug(f"No search results matched the expiry criteria.")
6870

6971
async def search_result_garbage_collector(
7072
clp_config: CLPConfig, log_directory: pathlib.Path, logging_level: str

components/job-orchestration/job_orchestration/garbage_collector/utils.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def validate_storage_type(output_config: ArchiveOutput, storage_engine: str) ->
4242
def get_expiry_epoch_secs(retention_minutes: int) -> int:
4343
"""
4444
Returns a cutoff `expiry_epoch` based on the current timestamp and `retention_minutes`. Any
45-
target with a timestamp (`ts`) less than `expiry_epoch` are considered expired.
45+
candidate with a timestamp (`ts`) less than `expiry_epoch` is considered expired.
4646
The `expiry_epoch` is calculated as `expiry_epoch = cur_time - retention_secs`.
4747
48-
:param: retention_minutes: Retention period in minutes.
49-
:return: The UTC epoch of the expiry time.
48+
:param retention_minutes: Retention period in minutes.
49+
:return: The UTC epoch representing the expiry cutoff time.
5050
"""
5151
return int(time.time() - retention_minutes * MIN_TO_SECONDS)
5252

@@ -55,16 +55,16 @@ def get_oid_with_expiry_time(expiry_epoch_secs: int) -> ObjectId:
5555
return ObjectId.from_datetime(datetime.fromtimestamp(expiry_epoch_secs, tz=timezone.utc))
5656

5757

58-
def execute_fs_deletion(fs_storage_config: FsStorage, deletion_candidate: str) -> None:
58+
def execute_fs_deletion(fs_storage_config: FsStorage, candidate: str) -> None:
5959
"""
60-
Deletes a target (either a directory or a file) from the filesystem storage. The full path
61-
of the target is constructed as `fs_storage_config.directory / target`. The function performs
62-
no action if the target does not exist.
60+
Deletes a candidate (either a directory or a file) from the filesystem storage. The full path
61+
of the candidate is constructed as `fs_storage_config.directory / candidate`. The function
62+
performs no action if the candidate does not exist.
6363
6464
:param fs_storage_config:
65-
:param deletion_candidate: Relative path of the file or directory to delete.
65+
:param candidate: Relative path of the file or directory to delete.
6666
"""
67-
path_to_delete = fs_storage_config.directory / deletion_candidate
67+
path_to_delete = fs_storage_config.directory / candidate
6868
if not path_to_delete.exists():
6969
return
7070

@@ -81,8 +81,8 @@ def execute_deletion(output_config: ArchiveOutput, deletion_candidates: Set[str]
8181
if StorageType.S3 == storage_type:
8282
s3_delete_objects(storage_config.s3_config, deletion_candidates)
8383
elif StorageType.FS == storage_type:
84-
for target in deletion_candidates:
85-
execute_fs_deletion(storage_config, target)
84+
for candidate in deletion_candidates:
85+
execute_fs_deletion(storage_config, candidate)
8686
else:
8787
raise ValueError(f"Unsupported Storage type: {storage_type}")
8888

@@ -115,24 +115,26 @@ def __init__(self, recovery_file_path: pathlib.Path):
115115
for line in f:
116116
self._candidates.add(line.strip())
117117

118-
def add_candidate(self, target: str) -> None:
119-
if target not in self._candidates:
120-
self._candidates.add(target)
121-
self._candidates_to_persist.append(target)
118+
def add_candidate(self, candidate: str) -> None:
119+
if candidate not in self._candidates:
120+
self._candidates.add(candidate)
121+
self._candidates_to_persist.append(candidate)
122122

123123
def get_candidates(self) -> Set[str]:
124124
return self._candidates
125125

126126
def persist_new_candidates(self) -> None:
127127
"""
128-
Writes any new candidates added since initialization to the recovery file.
128+
Writes any new candidates from `_candidates_to_persist` to the recovery file and clears
129+
the buffer.
130+
The method returns immediately without writing if `_candidates_to_persist` is empty.
129131
"""
130132
if len(self._candidates_to_persist) == 0:
131133
return
132134

133135
with open(self._recovery_file_path, "a") as f:
134-
for target in self._candidates_to_persist:
135-
f.write(f"{target}\n")
136+
for candidate in self._candidates_to_persist:
137+
f.write(f"{candidate}\n")
136138

137139
self._candidates_to_persist.clear()
138140

0 commit comments

Comments
 (0)