added no msrp prirority so they don't starve in queue
This commit is contained in:
1 parent
6c309b1e62
commit
dee090edaf
10 files changed
+1684
-1
No files matched your search
@@ -20,6 +20,11 @@ from monitor_utils.models import Product
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Drain rank for products with no MSRP. Their percentage is 0 by construction, so
|
||||
# without this they sort dead last and starve behind any backlog. 6 puts them
|
||||
# directly under the 70%+ band, tying with 60-69% and broken by createdAt.
|
||||
NO_MSRP_PRIORITY = 6
|
||||
|
||||
|
||||
def get_collection(collection_name: str) -> AsyncIOMotorCollection:
|
||||
"""Return the named collection from the shared client's database.
|
||||
@@ -282,7 +287,9 @@ def calculate_priority(document: dict) -> int:
|
||||
Always recalculated from current and original price so the priority
|
||||
reflects the prices at alert time rather than any stale stored
|
||||
percentage. Missing prices, zero original prices, and price increases
|
||||
resolve to priority 0.
|
||||
resolve to priority 0. A product with no MSRP has no percentage to rank
|
||||
on and takes NO_MSRP_PRIORITY instead, since a real 0 would leave it
|
||||
permanently behind every other alert in the claim query's sort.
|
||||
|
||||
Args:
|
||||
document: Product document supplying the prices.
|
||||
@@ -296,6 +303,9 @@ def calculate_priority(document: dict) -> int:
|
||||
if current_price is None or not original_price:
|
||||
return 0
|
||||
|
||||
if not document.get("hasMsrp", True):
|
||||
return NO_MSRP_PRIORITY
|
||||
|
||||
percentage = int(((original_price - current_price) / original_price) * 100)
|
||||
return min(max(percentage // 10, 0), 10)
|
||||
|
||||
|
||||
Reference in new issue
Block a user