Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/journal_client.py
Show All 26 Lines | def max_date(*dates: Optional[datetime]) -> datetime: | |||||||||||
filtered_dates = [d for d in dates if d is not None] | filtered_dates = [d for d in dates if d is not None] | |||||||||||
if not filtered_dates: | if not filtered_dates: | |||||||||||
raise ValueError("At least one date should be a valid datetime") | raise ValueError("At least one date should be a valid datetime") | |||||||||||
return max(filtered_dates) | return max(filtered_dates) | |||||||||||
def from_position_offset_to_days(position_offset: int) -> int: | def from_position_offset_to_days(position_offset: int) -> int: | |||||||||||
"""Compute position offset to interval in days. | """Compute position offset to interval in days. Bounds the position_offset to 10. | |||||||||||
- index 0 and 1: interval 1 day | - index 0 and 1: interval 1 day | |||||||||||
- index 2, 3 and 4: interval 2 days | - index 2, 3 and 4: interval 2 days | |||||||||||
- index 5 and up: interval `4^(n-4)` days for n in (4, 16, 64, 256, 1024, ...) | - index 5 and up: interval `4^(n-4)` days for n in [1:10]. | |||||||||||
Args: | Args: | |||||||||||
position_offset: The actual position offset for a given visit stats | position_offset: The actual position offset for a given visit stats | |||||||||||
Returns: | Returns: | |||||||||||
The offset as an interval in number of days | The offset as an interval in number of days | |||||||||||
""" | """ | |||||||||||
assert position_offset >= 0 | assert position_offset >= 0 | |||||||||||
if position_offset < 2: | if position_offset < 2: | |||||||||||
result = 1 | result = 1 | |||||||||||
elif position_offset < 5: | elif position_offset < 5: | |||||||||||
result = 2 | result = 2 | |||||||||||
else: | else: | |||||||||||
result = 4 ** (position_offset - 4) | exp = min(position_offset, 10) | |||||||||||
result = 4 ** (exp - 4) | ||||||||||||
ardumont: more like... | ||||||||||||
Done Inline Actionsoh come on, i meant min... ardumont: oh come on, i meant min... | ||||||||||||
return result | return result | |||||||||||
def next_visit_queue_position( | def next_visit_queue_position( | |||||||||||
queue_position_per_visit_type: Dict, visit_stats: Dict | queue_position_per_visit_type: Dict, visit_stats: Dict | |||||||||||
) -> datetime: | ) -> datetime: | |||||||||||
"""Compute the next visit queue position for the given visit_stats. | """Compute the next visit queue position for the given visit_stats. | |||||||||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | for msg_dict in interesting_messages: | |||||||||||
# Update the position offset according to the visit status, | # Update the position offset according to the visit status, | |||||||||||
# if we had already visited this origin before. | # if we had already visited this origin before. | |||||||||||
if visit_stats_d.get("last_visit"): | if visit_stats_d.get("last_visit"): | |||||||||||
# Update the next position offset according to the existing value and the | # Update the next position offset according to the existing value and the | |||||||||||
# eventfulness of the visit. | # eventfulness of the visit. | |||||||||||
increment = -2 if eventful else 1 | increment = -2 if eventful else 1 | |||||||||||
visit_stats_d["next_position_offset"] = max( | visit_stats_d["next_position_offset"] = max( | |||||||||||
0, visit_stats_d["next_position_offset"] + increment | 0, visit_stats_d["next_position_offset"] + increment | |||||||||||
) | ) | |||||||||||
ardumontAuthorUnsubmitted Done Inline Actions
or ^ which might be more readable... ardumont: or ^ which might be more readable...
| ||||||||||||
# increment the counter when last_visit_status is the same | # increment the counter when last_visit_status is the same | |||||||||||
same_visit_status = last_visit_status == visit_stats_d["last_visit_status"] | same_visit_status = last_visit_status == visit_stats_d["last_visit_status"] | |||||||||||
else: | else: | |||||||||||
same_visit_status = False | same_visit_status = False | |||||||||||
# Record current visit date as highest known date (we've rejected out of order | # Record current visit date as highest known date (we've rejected out of order | |||||||||||
# messages earlier). | # messages earlier). | |||||||||||
visit_stats_d["last_visit"] = msg_dict["date"] | visit_stats_d["last_visit"] = msg_dict["date"] | |||||||||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |
more like...