Item 3: route recommends a host worker while providers are down, and says what is down and what to do. done / next: item 4 worker notes
This commit is contained in:
1 parent
1208df9b1b
commit
3307fadee3
3 files changed
+55
No files matched your search
@@ -221,6 +221,8 @@ def choose(candidates, records, availability, kind, difficulty, review_of=None,
|
||||
|
||||
def load_ratio(c):
|
||||
left = c.get("allowance_pct_left")
|
||||
if left is None and c.get("host_native"):
|
||||
return 0.0 # a host worker has no allowance to spread work across: the record decides
|
||||
weight = float(left) if left else UNKNOWN_ALLOWANCE
|
||||
return stats.get(c["worker"], {}).get("uses", 0) / max(weight, 1.0)
|
||||
|
||||
|
||||
@@ -1291,6 +1291,22 @@ def cmd_workers(args=()):
|
||||
return 0
|
||||
|
||||
|
||||
def _down_now(avail, now):
|
||||
"""[(key, entry)] for every provider or worker marked down whose retry time is still ahead."""
|
||||
return [(k, v) for k, v in sorted((avail or {}).items())
|
||||
if isinstance(v, dict) and float(v.get("retry_at") or 0) > now]
|
||||
|
||||
|
||||
def _down_lines(down, limit=3):
|
||||
"""One line naming what is down and when each is due for another try, or nothing."""
|
||||
if not down:
|
||||
return []
|
||||
shown = ["%s (%s, next try %s)" % (k, v.get("reason") or "down", _when(v.get("retry_at")))
|
||||
for k, v in down[:limit]]
|
||||
more = " and %d more" % (len(down) - limit) if len(down) > limit else ""
|
||||
return ["down now: %s%s" % ("; ".join(shown), more)]
|
||||
|
||||
|
||||
def _route_setup(args):
|
||||
ensure_imported()
|
||||
kind = _opt(args, "--kind")
|
||||
@@ -1318,14 +1334,22 @@ def cmd_route(args=()):
|
||||
result = routing.choose(candidates, records, read_availability(), kind, difficulty,
|
||||
review_of=_opt(args, "--review-of"), now=time.time(),
|
||||
avoid=prefs["avoid"], prefer=prefs["prefer"])
|
||||
down = _down_now(read_availability(), time.time())
|
||||
if result["choice"] is None:
|
||||
print("no usable worker for kind %s at difficulty %d" % (kind, difficulty))
|
||||
for line in _down_lines(down):
|
||||
print(line)
|
||||
print("nothing is usable right now: the main agent does this task itself meanwhile, "
|
||||
"and tries `sisi route` again after the next-try time above%s."
|
||||
% ("" if down else " or once a worker is recorded or fixed (`sisi workers`)"))
|
||||
if "--explain" in args:
|
||||
for line in routing.explain_choice(result, kind, difficulty)[1:]:
|
||||
print(line)
|
||||
return 1
|
||||
print(result["choice"]["worker"])
|
||||
print("mechanism: %s" % mechanism_for(result["choice"]))
|
||||
for line in _down_lines(down):
|
||||
print(line)
|
||||
if "--explain" in args:
|
||||
for line in routing.explain_choice(result, kind, difficulty):
|
||||
print(line)
|
||||
|
||||
Reference in new issue
Block a user