Skip to content

Commit 67509f0

Browse files
committed
Renamed failback to ignore_unmatched
Signed-off-by: dpj135 <958208521@qq.com>
1 parent ad52a5c commit 67509f0

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

transfer_queue/storage/clients/yuanrong_client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def clear(self, keys: list[str], custom_backend_meta=None):
585585

586586
strategy_tags = custom_backend_meta
587587
routed_indexes = self._route_to_strategies(
588-
strategy_tags, lambda strategy_, item_: strategy_.supports_clear(item_), failback=True
588+
strategy_tags, lambda strategy_, item_: strategy_.supports_clear(item_), ignore_unmatched=True
589589
)
590590

591591
def clear_task(strategy, indexes):
@@ -598,7 +598,7 @@ def _route_to_strategies(
598598
self,
599599
items: list[Any],
600600
selector: Callable[[StorageStrategy, Any], bool],
601-
failback: bool = False,
601+
ignore_unmatched: bool = False,
602602
) -> dict[StorageStrategy, list[int]]:
603603
"""Groups item indices by the first strategy that supports them.
604604
@@ -618,18 +618,24 @@ def _route_to_strategies(
618618
A dictionary mapping each active strategy to a list of indexes in `items`
619619
that it should handle. Every index appears exactly once.
620620
"""
621+
unmatched_count = 0
621622
routed_indexes: dict[StorageStrategy, list[int]] = {s: [] for s in self._strategies}
622623
for i, item in enumerate(items):
623624
for strategy in self._strategies:
624625
if selector(strategy, item):
625626
routed_indexes[strategy].append(i)
626627
break
627628
else:
628-
if not failback:
629+
if ignore_unmatched:
630+
unmatched_count += 1
631+
else:
629632
raise ValueError(
630633
f"No strategy supports item of type {type(item).__name__}: {item}. "
631634
f"Available strategies: {[type(s).__name__ for s in self._strategies]}"
632635
)
636+
if unmatched_count > 0:
637+
logger.warning(f"{unmatched_count} items were not matched to any strategy and will be ignored.")
638+
633639
return routed_indexes
634640

635641
@staticmethod

0 commit comments

Comments
 (0)